php-composer 0.4.5 → 1.0.0.pre.alpha11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rbenv-gemsets +1 -0
  3. data/.rubocop.yml +131 -188
  4. data/.ruby-version +1 -0
  5. data/Gemfile +0 -9
  6. data/Rakefile +11 -0
  7. data/lib/composer.rb +52 -49
  8. data/lib/composer/json/json_file.rb +110 -83
  9. data/lib/composer/json/json_formatter.rb +43 -77
  10. data/lib/composer/json/{json_validaton_error.rb → json_validation_error.rb} +6 -2
  11. data/lib/composer/package/alias_package.rb +77 -61
  12. data/lib/composer/package/complete_package.rb +88 -18
  13. data/lib/composer/package/dumper/hash_dumper.rb +50 -118
  14. data/lib/composer/package/dumper/hash_dumper/complete_package_attribute_dumpers.rb +47 -0
  15. data/lib/composer/package/dumper/hash_dumper/package_attribute_dumpers.rb +145 -0
  16. data/lib/composer/package/dumper/hash_dumper/root_package_attribute_dumpers.rb +24 -0
  17. data/lib/composer/package/link.rb +15 -5
  18. data/lib/composer/package/loader/hash_loader.rb +92 -228
  19. data/lib/composer/package/loader/hash_loader/complete_package_attribute_loaders.rb +83 -0
  20. data/lib/composer/package/loader/hash_loader/package_attribute_loaders.rb +181 -0
  21. data/lib/composer/package/loader/hash_loader/root_package_attribute_loaders.rb +32 -0
  22. data/lib/composer/package/loader/json_loader.rb +7 -9
  23. data/lib/composer/package/package.rb +611 -43
  24. data/lib/composer/package/root_alias_package.rb +186 -15
  25. data/lib/composer/package/root_package.rb +12 -4
  26. data/lib/composer/package/version/version_parser.rb +16 -532
  27. data/lib/composer/package/version/version_selector.rb +127 -68
  28. data/lib/composer/repository/base_repository.rb +46 -3
  29. data/lib/composer/repository/composite_repository.rb +4 -4
  30. data/lib/composer/repository/filesystem_repository.rb +15 -8
  31. data/lib/composer/repository/hash_repository.rb +62 -45
  32. data/lib/composer/repository/writeable_hash_repository.rb +5 -5
  33. data/lib/composer/util/composer_mirror.rb +76 -0
  34. data/php-composer.gemspec +14 -8
  35. data/resources/composer-schema.json +12 -0
  36. metadata +117 -16
  37. data/lib/composer/error.rb +0 -8
  38. data/lib/composer/package/base_package.rb +0 -130
  39. data/lib/composer/package/link_constraint/base_constraint.rb +0 -36
  40. data/lib/composer/package/link_constraint/empty_constraint.rb +0 -35
  41. data/lib/composer/package/link_constraint/multi_constraint.rb +0 -67
  42. data/lib/composer/package/link_constraint/specific_constraint.rb +0 -41
  43. data/lib/composer/package/link_constraint/version_constraint.rb +0 -221
  44. data/lib/composer/version.rb +0 -3
@@ -0,0 +1,181 @@
1
+ #
2
+ # This file was ported to ruby from Composer php source code.
3
+ #
4
+ # Original Source: Composer\Package\Loader\ArrayLoader.php
5
+ # Ref SHA: a1427d7fd626d4308c190a267dd7a993f87c6a2a
6
+ #
7
+ # (c) Nils Adermann <naderman@naderman.de>
8
+ # Jordi Boggiano <j.boggiano@seld.be>
9
+ #
10
+ # For the full copyright and license information, please view the LICENSE
11
+ # file that was distributed with this source code.
12
+ #
13
+
14
+ module Composer
15
+ module Package
16
+ module Loader
17
+ class HashLoader
18
+
19
+ attr_loader :type do |config, package|
20
+ if config.key? 'type'
21
+ package.type = config['type'].downcase
22
+ else
23
+ package.type = 'library'
24
+ end
25
+ end
26
+
27
+ attr_loader :target_dir
28
+
29
+ attr_loader :extra do |config, package|
30
+ if config.key?('extra') && config['extra'].is_a?(Hash)
31
+ package.extra = config['extra']
32
+ end
33
+ end
34
+
35
+ attr_loader :binaries do |config, package|
36
+ if config.key?('bin')
37
+ unless config['bin'].is_a?(Array)
38
+ raise UnexpectedValueError,
39
+ "Package #{config['name']}'s bin key should be an hash,\n
40
+ #{config['bin'].class.name} given."
41
+ end
42
+ config['bin'].each do |bin|
43
+ bin.gsub!(/^\/+/, '')
44
+ end
45
+ package.binaries = config['bin']
46
+ end
47
+ end
48
+
49
+ attr_loader :installation_source
50
+
51
+ attr_loader :source do |config, package|
52
+ if config.key?('source')
53
+ if [:type, :url, :reference].all? {|k| config['source'].key? k}
54
+ raise UnexpectedValueError,
55
+ "Package #{config['name']}'s source key should be specified as\n
56
+ {\"type\": ..., \"url\": ..., \"reference\": ...}, \n
57
+ #{config['source'].to_json} given."
58
+ end
59
+ package.source_type = config['source']['type']
60
+ package.source_url = config['source']['url']
61
+ package.source_reference = config['source']['reference']
62
+ if config['source'].key?('mirrors')
63
+ package.source_mirrors = config['source']['mirrors']
64
+ end
65
+ end
66
+ end
67
+
68
+ attr_loader :dist do |config, package|
69
+ if config.key?('dist')
70
+ if [:type, :url].all? {|k| config['dist'].key? k}
71
+ raise UnexpectedValueError,
72
+ "Package #{config['name']}'s dist key should be specified as\n
73
+ {\"type\": ..., \"url\": ..., \"reference\": ..., \"shasum\": ...},\n
74
+ #{config['dist'].to_json} given."
75
+ end
76
+ package.dist_type = config['dist']['type']
77
+ package.dist_url = config['dist']['url']
78
+ package.dist_reference = config['dist'].key?('reference') ? config['dist']['reference'] : nil
79
+ package.dist_sha1_checksum = config['dist'].key?('shasum') ? config['dist']['shasum'] : nil
80
+ if config['dist'].key?('mirrors')
81
+ package.dist_mirrors = config['dist']['mirrors']
82
+ end
83
+ end
84
+ end
85
+
86
+ SUPPORTED_LINK_TYPES.each do |type, opts|
87
+ attr_loader opts[:method] do |config, package|
88
+ if config.key?(type)
89
+ package.send(
90
+ "#{opts[:method]}=",
91
+ parse_links(
92
+ package.name,
93
+ package.pretty_version,
94
+ opts[:description],
95
+ config[type]
96
+ )
97
+ )
98
+ end
99
+ end
100
+ end
101
+
102
+ attr_loader :suggests do |config, package|
103
+ if config.key?('suggest') && config['suggest'].is_a?(Hash)
104
+ config['suggest'].each do |target, reason|
105
+ if 'self.version' === reason.strip!
106
+ config['suggest'][target] = package.pretty_version
107
+ end
108
+ end
109
+ package.suggests = config['suggest']
110
+ end
111
+ end
112
+
113
+ attr_loader :autoload
114
+
115
+ attr_loader :dev_autoload, from: 'autoload-dev'
116
+
117
+ attr_loader :include_paths, from: 'include-path'
118
+
119
+ attr_loader :release_date, from: 'time' do |config, package|
120
+ if config.key?('time')
121
+ unless config['time'].empty?
122
+ time = config['time'] =~ /[[:digit:]]/ ? "@#{config['time']}" : config['time']
123
+ date = Time.zone.parse(time) rescue false
124
+ package.release_date = date unless date
125
+ end
126
+ end
127
+ end
128
+
129
+ attr_loader :notification_url do |config, package|
130
+ if config.key?('notification-url')
131
+ unless config['notification-url'].empty?
132
+ package.notification_url = config['notification-url']
133
+ end
134
+ end
135
+ end
136
+
137
+ attr_loader :archive_excludes do |config, package|
138
+ if config.key?('archive')
139
+ if config['archive'].key?('exclude')
140
+ unless config['archive']['exclude'].empty?
141
+ package.archive_excludes = config['archive']['exclude']
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ ##
148
+ # @param source string
149
+ # The source package name
150
+ # @param source_version string
151
+ # The source package version (pretty version ideally)
152
+ # @param description string
153
+ # The link description (e.g. requires, replaces, ..)
154
+ # @param links hash
155
+ # The hash of package name => constraint mappings
156
+ #
157
+ # @return Link{}
158
+ ##
159
+ def parse_links(source, source_version, description, links)
160
+ res = {}
161
+ links.each do |target, constraint|
162
+ if 'self.version' === constraint
163
+ parsed_constraint = @version_parser.parse_constraints(source_version)
164
+ else
165
+ parsed_constraint = @version_parser.parse_constraints(constraint)
166
+ end
167
+ res[target.downcase] = Composer::Package::Link.new(
168
+ source,
169
+ target,
170
+ parsed_constraint,
171
+ description,
172
+ constraint
173
+ )
174
+ end
175
+ res
176
+ end
177
+
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # This file was ported to ruby from Composer php source code.
3
+ #
4
+ # Original Source: Composer\Package\Loader\ArrayLoader.php
5
+ # Ref SHA: a1427d7fd626d4308c190a267dd7a993f87c6a2a
6
+ #
7
+ # (c) Nils Adermann <naderman@naderman.de>
8
+ # Jordi Boggiano <j.boggiano@seld.be>
9
+ #
10
+ # For the full copyright and license information, please view the LICENSE
11
+ # file that was distributed with this source code.
12
+ #
13
+
14
+ module Composer
15
+ module Package
16
+ module Loader
17
+ class HashLoader
18
+
19
+ # on_load ::Composer::Package::RootPackage do |config, package|
20
+ #
21
+ # if config.key?('minimum-stabitily')
22
+ # package.minimum_stability = config['minimum-stability']
23
+ # end
24
+ #
25
+ # end
26
+
27
+ attr_loader :minimum_stability
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,6 +1,8 @@
1
1
  #
2
2
  # This file was ported to ruby from Composer php source code.
3
+ #
3
4
  # Original Source: Composer\Package\Loader\JsonLoader.php
5
+ # Ref SHA: ef637c8f1a894157e2f012ad3571183f12fde19f
4
6
  #
5
7
  # (c) Nils Adermann <naderman@naderman.de>
6
8
  # Jordi Boggiano <j.boggiano@seld.be>
@@ -26,17 +28,13 @@ module Composer
26
28
  # Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from
27
29
  # Returns: Composer::Package::Package
28
30
  def load(json)
29
- if json.instance_of?(Composer::Json::JsonFile)
31
+ if json.kind_of? ::Composer::Json::JsonFile
30
32
  config = json.read
31
33
  elsif File.exists?(json)
32
- config = Composer::Json::JsonFile.parse_json(
33
- File.open(filepath, "r") { |f| f.read },
34
- json
35
- )
36
- elsif json.class === "String"
37
- config = Composer::Json::JsonFile.parse_json(
38
- json
39
- )
34
+ content = File.open(json, 'r') { |f| f.read }
35
+ config = ::Composer::Json::JsonFile.parse_json content, json
36
+ elsif json.is_a? String
37
+ config = ::Composer::Json::JsonFile.parse_json json
40
38
  end
41
39
  @loader.load(config)
42
40
  end
@@ -9,41 +9,106 @@
9
9
  # file that was distributed with this source code.
10
10
  #
11
11
 
12
+ require 'composer/semver'
13
+
12
14
  module Composer
13
15
  module Package
14
16
 
15
- # Core package definitions that are needed to resolve dependencies
16
- # and install packages
17
- class Package < Composer::Package::BasePackage
17
+ SUPPORTED_LINK_TYPES = {
18
+ 'require' => {
19
+ description: 'requires',
20
+ method: 'requires'
21
+ },
22
+ 'conflict' => {
23
+ description: 'conflicts',
24
+ method: 'conflicts'
25
+ },
26
+ 'provide' => {
27
+ description: 'provides',
28
+ method: 'provides'
29
+ },
30
+ 'replace' => {
31
+ description: 'replaces',
32
+ method: 'replaces'
33
+ },
34
+ 'require-dev' => {
35
+ description: 'requires (for development)',
36
+ method: 'dev_requires'
37
+ }
38
+ }.freeze
18
39
 
19
- attr_reader :stability
40
+ STABILITY_STABLE = 0
41
+ STABILITY_RC = 5
42
+ STABILITY_BETA = 10
43
+ STABILITY_ALPHA = 15
44
+ STABILITY_DEV = 20
20
45
 
21
- attr_accessor :installation_source, :source_type,
22
- :source_url, :source_reference, :source_mirrors, :dist_type,
23
- :dist_url, :dist_reference, :dist_sha1_checksum,
24
- :dist_mirrors, :release_date, :extra, :binaries, :requires,
25
- :conflicts, :provides, :replaces, :dev_requires, :suggests,
26
- :autoload, :dev_autoload, :include_paths, :archive_excludes,
27
- :notification_url
28
-
29
- # complete package attributes
46
+ STABILITIES = {
47
+ 'stable' => STABILITY_STABLE,
48
+ 'RC' => STABILITY_RC,
49
+ 'beta' => STABILITY_BETA,
50
+ 'alpha' => STABILITY_ALPHA,
51
+ 'dev' => STABILITY_DEV,
52
+ }.freeze()
30
53
 
54
+ ##
55
+ # Core package definitions that are needed to resolve dependencies
56
+ # and install packages
57
+ ##
58
+ class Package
31
59
 
60
+ ##
32
61
  # Creates a new in memory package.
33
- # Param: string name The package's name
34
- # Param: string version The package's version
35
- # Param: string prettyVersion The package's non-normalized version
62
+ #
63
+ # @param name string
64
+ # The package's name
65
+ # @param version string
66
+ # The package's version
67
+ # @param: pretty_version string
68
+ # The package's non-normalized version
69
+ ##
36
70
  def initialize(name, version, pretty_version)
37
- super(name)
71
+
72
+ @pretty_name = name
73
+ @name = name.downcase
74
+ @id = -1
75
+ @transport_options = []
76
+ @repository = nil
77
+ @type = nil
38
78
 
39
79
  # default values
80
+ @type = nil
81
+ @target_dir = nil
82
+ @installation_source = nil
83
+ @source_type = nil
84
+ @source_url = nil
85
+ @source_reference = nil
86
+ @source_mirrors = nil
87
+ @dist_type = nil
88
+ @dist_url = nil
89
+ @dist_reference = nil
90
+ @dist_sha1_checksum = nil
91
+ @dist_mirrors = nil
92
+ @version = nil
93
+ @pretty_version = nil
94
+ @release_date = nil
40
95
  @extra = {}
41
96
  @binaries = []
97
+ @dev = nil
98
+ @stability = nil
99
+ @notification_url = nil
100
+
101
+ # @var Hash of package name => Link
42
102
  @requires = {}
103
+ # @var Hash of package name => Link
43
104
  @conflicts = {}
105
+ # @var Hash of package name => Link
44
106
  @provides = {}
107
+ # @var Hash of package name => Link
45
108
  @replaces = {}
109
+ # @var Hash of package name => Link
46
110
  @dev_requires = {}
111
+
47
112
  @suggests = {}
48
113
  @autoload = {}
49
114
  @dev_autoload = {}
@@ -55,62 +120,565 @@ module Composer
55
120
 
56
121
  end
57
122
 
58
- def attributes
59
- dumper = Composer::Package::Dumper::HashDumper.new
60
- dumper.dump(self)
123
+ ##
124
+ # Returns whether the package is a development virtual package or a concrete one
125
+ # @return bool
126
+ ##
127
+ def is_dev?
128
+ @dev
61
129
  end
62
130
 
63
- # Set package type
64
- # Param: string type
65
- def type=(type)
66
- @type = type
131
+ ##
132
+ # Allows the solver to set an id for this package to refer to it.
133
+ #
134
+ # @param id integer
135
+ ##
136
+ attr_writer :id
137
+
138
+ ##
139
+ # Retrieves the package's id
140
+ #
141
+ # @return int The previously set package id
142
+ ##
143
+ attr_reader :id
144
+
145
+ ##
146
+ # Get the package name
147
+ #
148
+ # @return string
149
+ ##
150
+ attr_reader :name
151
+
152
+ ##
153
+ # Get the package pretty name
154
+ #
155
+ # @return string
156
+ ##
157
+ attr_reader :pretty_name
158
+
159
+ ##
160
+ # Returns a set of names that could refer to this package
161
+ #
162
+ # No version or release type information should be included in any of the
163
+ # names. Provided or replaced package names need to be returned as well.
164
+ #
165
+ # @return array An array of strings referring to this package
166
+ ##
167
+ def names
168
+ names = {}
169
+
170
+ names[name] = true
171
+
172
+ provides.each do |link|
173
+ names[link.target] = true
174
+ end
175
+
176
+ replaces.each do |link|
177
+ names[link.target] = true
178
+ end
179
+
180
+ names.keys
67
181
  end
68
182
 
69
- # Get package type
70
- # Return: string
183
+
184
+ ##
185
+ # Set the package type.
186
+ # @param type string
187
+ ##
188
+ attr_writer :type
189
+
190
+ ##
191
+ # Get package type.
192
+ # @return string
71
193
  def type
72
194
  @type ? @type : 'library'
73
195
  end
74
196
 
75
- def target_dir=(target_dir)
76
- @target_dir = target_dir
197
+ ##
198
+ # Get the package stability.
199
+ #
200
+ # @return string|nil
201
+ ##
202
+ attr_reader :stability
203
+
204
+ ##
205
+ # Get the package stability priority.
206
+ ##
207
+ def stability_priority
208
+ ::Composer::Package::STABILITIES[stability]
77
209
  end
78
210
 
211
+ ##
212
+ # Set the target directory
213
+ # @param target_dir string
214
+ ##
215
+ attr_writer :target_dir
216
+
217
+ ##
218
+ # Get target directory
219
+ # @return string| nil
220
+ #
79
221
  def target_dir
80
- return unless @target_dir
222
+ return if @target_dir.nil?
81
223
  regex = '(?:^|[\\\\/]+)\.\.?(?:[\\\\/]+|$)(?:\.\.?(?:[\\\\/]+|$))*'
82
224
  @target_dir.gsub(/#{regex}/x, '/').gsub(/^\/+/, '')
83
225
  end
84
226
 
85
- # Returns package unique name, constructed from name, version and
86
- # release type.
87
- # Return: string
88
- def unique_name
89
- "#{name}-#{version}"
227
+ ##
228
+ # Set the package extra
229
+ # @param extra Hash
230
+ ##
231
+ attr_writer :extra
232
+
233
+ ##
234
+ # Get the package extra
235
+ # @return Hash
236
+ ##
237
+ attr_reader :extra
238
+
239
+ ##
240
+ # Set the package binaries
241
+ # @param binaries Array
242
+ ##
243
+ attr_writer :binaries
244
+
245
+ ##
246
+ # Get the package binaries
247
+ # @return Hash|nil
248
+ ##
249
+ attr_reader :binaries
250
+
251
+ ##
252
+ # Set the package installation source
253
+ # @param installation_source string
254
+ ##
255
+ attr_writer :installation_source
256
+
257
+ ##
258
+ # Get the package installation source
259
+ # @return string|nil
260
+ ##
261
+ attr_reader :installation_source
262
+
263
+ ##
264
+ # Set the package source type
265
+ # @param source_type string
266
+ ##
267
+ attr_writer :source_type
268
+
269
+ ##
270
+ # Get the package source type
271
+ # @return string|nil
272
+ ##
273
+ attr_reader :source_type
274
+
275
+ ##
276
+ # Set the package source url
277
+ # @param source_url string
278
+ ##
279
+ attr_writer :source_url
280
+
281
+ ##
282
+ # Get the package source url
283
+ # @return string|nil
284
+ ##
285
+ attr_reader :source_url
286
+
287
+ ##
288
+ # Set the package source reference
289
+ # @param source_reference string
290
+ ##
291
+ attr_writer :source_reference
292
+
293
+ ##
294
+ # Get the package source reference
295
+ # @return string|nil
296
+ ##
297
+ attr_reader :source_reference
298
+
299
+ # Get/Set the package source mirrors
300
+ # @param source_mirrors array|nil
301
+ ##
302
+ attr_writer :source_mirrors
303
+
304
+ ##
305
+ # Get the package source mirrors
306
+ # @return string|nil
307
+ ##
308
+ attr_reader :source_mirrors
309
+
310
+ ##
311
+ # Get the package source urls
312
+ # @return array
313
+ ##
314
+ def source_urls
315
+ get_urls( source_url, source_mirrors, source_reference, source_type, 'source')
90
316
  end
91
317
 
92
- def pretty_string
93
- "#{pretty_name} #{pretty_version}"
318
+ ##
319
+ # Set the package distribution type
320
+ # @param dist_type string
321
+ ##
322
+ attr_writer :dist_type
323
+
324
+ ##
325
+ # Get the package distribution type
326
+ # @return string|nil
327
+ ##
328
+ attr_reader :dist_type
329
+
330
+ ##
331
+ # Set the package distribution url
332
+ # @param dist_url string
333
+ ##
334
+ attr_writer :dist_url
335
+
336
+ ##
337
+ # Get the package distribution url
338
+ # @return string|nil
339
+ ##
340
+ attr_reader :dist_url
341
+
342
+ ##
343
+ # Set the package distribution reference
344
+ # @param dist_reference string
345
+ ##
346
+ attr_writer :dist_reference
347
+
348
+ ##
349
+ # Get the package distribution reference
350
+ # @return string|nil
351
+ ##
352
+ attr_reader :dist_reference
353
+
354
+ ##
355
+ # Set the package distribution sha1 checksum
356
+ # @param dist_sha1_checksum string
357
+ ##
358
+ attr_writer :dist_sha1_checksum
359
+
360
+ ##
361
+ # Get the package distribution sha1 checksum
362
+ # @return string|nil
363
+ ##
364
+ attr_reader :dist_sha1_checksum
365
+
366
+ ##
367
+ # Set the package distribution mirrors
368
+ # @param dist_mirrors string
369
+ ##
370
+ attr_writer :dist_mirrors
371
+
372
+ ##
373
+ # Get the package distribution mirrors
374
+ # @return string|nil
375
+ ##
376
+ attr_reader :dist_mirrors
377
+
378
+ ##
379
+ # Get the package distribution urls
380
+ # @return array
381
+ ##
382
+ def dist_urls
383
+ get_urls( dist_url, dist_mirrors, dist_reference, dist_type, 'dist' )
94
384
  end
95
385
 
96
- # Determine if development package
97
- # Return: true if development package; Otherwise false.
98
- def is_dev
99
- @dev
386
+ ##
387
+ # Get the package version
388
+ # @return string
389
+ ##
390
+ attr_reader :version
391
+
392
+ ##
393
+ # Get the package pretty version
394
+ # @return string
395
+ ##
396
+ attr_reader :pretty_version
397
+
398
+ ##
399
+ # Returns the pretty version string plus a git or hg commit hash of this package
400
+ #
401
+ # @see pretty_version
402
+ #
403
+ # @param truncate bool
404
+ # If the source reference is a sha1 hash, truncate it
405
+ #
406
+ # @return string
407
+ ##
408
+ def full_pretty_version(truncate = true)
409
+ unless is_dev? || %w{hg git}.include?(source_type)
410
+ return pretty_version
411
+ end
412
+
413
+ # if source reference is a sha1 hash -- truncate
414
+ if truncate && source_reference.length === 40
415
+ return "#{pretty_version} #{source_reference[0..6]}"
416
+ end
417
+
418
+ "#{pretty_version} #{source_reference}"
100
419
  end
101
420
 
421
+ ##
102
422
  # Replaces current version and pretty version with passed values.
103
423
  # It also sets stability.
104
- # Param: string version The package's normalized version
105
- # Param: string prettyVersion The package's non-normalized version
424
+ #
425
+ # @param version string version
426
+ # The package's normalized version
427
+ # @param pretty_version string
428
+ # The package's non-normalized version
429
+ ##
106
430
  def replace_version(version, pretty_version)
107
431
  @version = version
108
432
  @pretty_version = pretty_version
109
433
 
110
- @stability = Composer::Package::Version::VersionParser::parse_stability(version)
434
+ @stability = ::Composer::Semver::VersionParser::parse_stability(version)
111
435
  @dev = @stability === 'dev'
112
436
  end
113
437
 
438
+ ##
439
+ # Set the package release date
440
+ # @param release_date Date
441
+ ##
442
+ attr_writer :release_date
443
+
444
+ ##
445
+ # Get the package release date
446
+ # @return Date|nil
447
+ ##
448
+ attr_reader :release_date
449
+
450
+ ##
451
+ # Set the package requires
452
+ # @param requires Hash of package name => Link
453
+ ##
454
+ attr_writer :requires
455
+
456
+ ##
457
+ # Get the package requires
458
+ # @return Hash of package name => Link
459
+ ##
460
+ attr_reader :requires
461
+
462
+ ##
463
+ # Set the package conflicts
464
+ # @param conflicts Hash of package name => Link
465
+ ##
466
+ attr_writer :conflicts
467
+
468
+ ##
469
+ # Get the package conflicts
470
+ # @return Hash of package name => Link
471
+ ##
472
+ attr_reader :conflicts
473
+
474
+ ##
475
+ # Set the package provides
476
+ # @param provides Hash of package name => Link
477
+ ##
478
+ attr_writer :provides
479
+
480
+ ##
481
+ # Get the package provides
482
+ # @return Hash of package name => Link
483
+ ##
484
+ attr_reader :provides
485
+
486
+ ##
487
+ # Set the package replaces
488
+ # @param replaces Hash of package name => Link
489
+ ##
490
+ attr_writer :replaces
491
+
492
+ ##
493
+ # Get the package replaces
494
+ # @return Hash of package name => Link
495
+ ##
496
+ attr_reader :replaces
497
+
498
+ ##
499
+ # Set the package dev requires
500
+ # @param dev_requires Hash of package name => Link
501
+ ##
502
+ attr_writer :dev_requires
503
+
504
+ ##
505
+ # Get the package dev requires
506
+ # @return Hash of package name => Link
507
+ ##
508
+ attr_reader :dev_requires
509
+
510
+ ##
511
+ # Set the package suggests
512
+ # @param suggests Hash of package name => comments
513
+ ##
514
+ attr_writer :suggests
515
+
516
+ ##
517
+ # Get the package suggests
518
+ # @return Hash of package name => Link
519
+ ##
520
+ attr_reader :suggests
521
+
522
+ ##
523
+ # Set the package autoload mapping
524
+ # @param autoload Hash Mapping of auto-loading rules
525
+ ##
526
+ attr_writer :autoload
527
+
528
+ ##
529
+ # Get the package autoload mapping
530
+ # TODO: This conflicts with kernel method autoload
531
+ # @return Array
532
+ ##
533
+ attr_reader :autoload
534
+
535
+ ##
536
+ # Set the package dev autoload mapping
537
+ # @param dev_autoload Array Mapping of dev auto-loading rules
538
+ ##
539
+ attr_writer :dev_autoload
540
+
541
+ ##
542
+ # Get the package dev autoload mapping
543
+ # @return Array
544
+ ##
545
+ attr_reader :dev_autoload
546
+
547
+ ##
548
+ # Set the list of paths added to PHP's include path.
549
+ # @param include_paths Array List of directories
550
+ ##
551
+ attr_writer :include_paths
552
+
553
+ ##
554
+ # Get the package include_paths mapping
555
+ # @return Array
556
+ ##
557
+ attr_reader :include_paths
558
+
559
+ ##
560
+ # Set the package notification url
561
+ # @param notification_url string
562
+ ##
563
+ attr_writer :notification_url
564
+
565
+ ##
566
+ # Get the package notification url
567
+ # @return string|nil
568
+ ##
569
+ attr_reader :notification_url
570
+
571
+ # Set a list of patterns to be excluded from archives
572
+ # @param archive_excludes Array
573
+ ##
574
+ attr_writer :archive_excludes
575
+
576
+ ##
577
+ # Get the package archive_excludes mapping
578
+ # @return Array
579
+ ##
580
+ attr_reader :archive_excludes
581
+
582
+ ##
583
+ # Set the list of options to download package dist files
584
+ # @param transport_options array
585
+ ##
586
+ attr_writer :transport_options
587
+
588
+ ##
589
+ # Returns a list of options to download package dist files
590
+ # @return array
591
+ ##
592
+ attr_reader :transport_options
593
+
594
+ ##
595
+ # Stores a reference to the repository that owns the package
596
+ # @param repository ::Composer::Repository::Repository
597
+ ##
598
+ def repository=(repository)
599
+ unless @repository.nil? || @repository.equal?(repository)
600
+ raise LogicError,
601
+ 'A package can only be added to one repository'
602
+ end
603
+ @repository = repository
604
+ end
605
+
606
+ ##
607
+ # Returns a reference to the repository that owns the package
608
+ # @return RepositoryInterface
609
+ ##
610
+ attr_reader :repository
611
+
612
+ ##
613
+ # Returns package unique name, constructed from name and version.
614
+ # @return string
615
+ ##
616
+ def unique_name
617
+ "#{name}-#{version}"
618
+ end
619
+
620
+ ##
621
+ # Converts the package into a readable and unique string
622
+ # @return string
623
+ ##
624
+ def to_s
625
+ unique_name
626
+ end
627
+
628
+ ##
629
+ # Converts the package into a pretty readable string
630
+ # @return string
631
+ ##
632
+ def pretty_string
633
+ "#{pretty_name} #{pretty_version}"
634
+ end
635
+
636
+ def is_platform?
637
+ # repository.instance_of?(PlatformRepository)
638
+ false
639
+ end
640
+
641
+ ##
642
+ # Determine whether the specified package is equal to this package.
643
+ # @param package
644
+ ##
645
+ def equal?(package)
646
+ target = self
647
+ if self.kind_of? ::Composer::Package::AliasPackage
648
+ target = alias_of
649
+ end
650
+ if package.kind_of? ::Composer::Package::AliasPackage
651
+ package = package.alias_of
652
+ end
653
+ package === target
654
+ end
655
+
656
+ protected
657
+
658
+ ##
659
+ # Helper method to combine urls by type
660
+ ##
661
+ def get_urls(url, mirrors, ref, type, url_type)
662
+ return [] if url.nil?
663
+ urls = [ url ]
664
+ if mirrors
665
+ mirrors.each do |mirror|
666
+ if url_type === 'dist'
667
+ mirror_url = ::Composer::Util::ComposerMirror::process_url(mirror['url'], name, version, ref, type)
668
+ elsif url_type === 'source' && type === 'git'
669
+ mirror_url = ::Composer::Util::ComposerMirror::process_git_url(mirror['url'], name, url, type)
670
+ elsif url_type === 'source' && type === 'hg'
671
+ mirror_url = ::Composer::Util::ComposerMirror::process_hg_url(mirror['url'], name, url, type)
672
+ end
673
+ unless urls.include? mirror_url
674
+ func = mirror['preferred'] ? 'unshift' : 'push'
675
+ urls.send(func, mirror_url)
676
+ end
677
+ end
678
+ end
679
+ urls
680
+ end
681
+
114
682
  end
115
683
  end
116
684
  end