php-composer 0.4.5 → 1.0.0.pre.alpha11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -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\Dumper\ArrayDumper.php
5
+ # Ref SHA: 346133d2a112dbc52163eceeee67814d351efe3f
4
6
  #
5
7
  # (c) Nils Adermann <naderman@naderman.de>
6
8
  # Jordi Boggiano <j.boggiano@seld.be>
@@ -12,6 +14,7 @@
12
14
  module Composer
13
15
  module Package
14
16
  module Dumper
17
+
15
18
  # Dumps a hash from a package
16
19
  #
17
20
  # PHP Authors:
@@ -21,148 +24,77 @@ module Composer
21
24
  # Ruby Authors:
22
25
  # Ioannis Kappas <ikappas@devworks.gr>
23
26
  class HashDumper
24
- def dump(package)
25
- keys = {
26
- 'binaries' => 'bin',
27
- 'type' => 'type',
28
- 'extra' => 'extra',
29
- 'installation_source' => 'installation-source',
30
- 'autoload' => 'autoload',
31
- 'dev_autoload' => 'autoload-dev',
32
- 'notification_url' => 'notification-url',
33
- 'include_paths' => 'include-path',
34
- }
35
27
 
36
- data = {}
37
- data['name'] = package.pretty_name
38
- data['version'] = package.pretty_version
39
- data['version_normalized'] = package.version
28
+ class << self
40
29
 
41
- if package.target_dir
42
- data['target-dir'] = package.target_dir
30
+ def attr_dumpers
31
+ @attr_dumpers ||= []
43
32
  end
44
33
 
45
- if package.source_type
46
- data['source'] = {}
47
- data['source']['type'] = package.source_type
48
- data['source']['url'] = package.source_url
49
- data['source']['reference'] = package.source_reference
50
- if mirrors = package.source_mirrors
51
- data['source']['mirrors'] = mirrors
34
+ def attr_dumper( attr, options = {}, &block)
35
+ if block_given?
36
+ attr_dumpers.push({ attr: attr, options: options, callback: block })
37
+ else
38
+ attr_dumpers.push({ attr: attr, options: options })
52
39
  end
53
40
  end
54
41
 
55
- if package.dist_type
56
- data['dist'] = {}
57
- data['dist']['type'] = package.dist_type
58
- data['dist']['url'] = package.dist_url
59
- data['dist']['reference'] = package.dist_reference
60
- data['dist']['shasum'] = package.dist_sha1_checksum
61
- if mirrors = package.dist_mirrors
62
- data['dist']['mirrors'] = mirrors
63
- end
64
- end
42
+ end
65
43
 
66
- unless package.archive_excludes.nil? || package.archive_excludes.empty?
67
- data['archive'] = {}
68
- data['archive']['exclude'] = package.archive_excludes
69
- end
44
+ def dump(package)
70
45
 
71
- Composer::Package::BasePackage::SUPPORTED_LINK_TYPES.each do |type, opts|
72
- next unless links = package.send(opts['method'])
73
- next if links.nil?
74
- next if links.is_a?(Array) && links.empty?
75
- next if links.is_a?(Hash) && links.empty?
76
- data[type] = {} unless data.key?(type)
77
- values = links.is_a?(Hash) ? links.values : links
78
- values.each do |link|
79
- data[type][link.target] = link.pretty_constraint
80
- end
81
- data[type].keys.sort.each do |k|
82
- data[type][k] = data[type].delete k
83
- end
46
+ # verify supplied arguments
47
+ unless package
48
+ raise ArgumentError,
49
+ 'Invalid package configuration supplied.'
84
50
  end
85
51
 
86
- if packages = package.suggests
87
- unless packages.nil? || packages.empty?
88
- packages.keys.sort.each do |k|
89
- packages[k] = packages.delete k
90
- end
91
- data['suggest'] = packages
92
- end
52
+ unless package.respond_to?(:pretty_name)
53
+ raise UnexpectedValueError,
54
+ 'The package specified is missing the "pretty_name" method.'
93
55
  end
94
56
 
95
- if package.release_date && !package.release_date.nil?
96
- data['time'] = package.release_date.strftime('%Y-%m-%d %H:%M:%S')
57
+ unless package.respond_to?(:pretty_version)
58
+ raise UnexpectedValueError,
59
+ 'The package specified is missing the "pretty_version" method.'
97
60
  end
98
61
 
99
- data = dump_values(package, keys, data)
100
-
101
- # if data.key?('type') && data['type'] === 'library'
102
- # data.delete('type')
103
- # end
104
-
105
- if package.is_a?(Composer::Package::CompletePackage)
106
- keys = %w{scripts license authors description homepage keywords repositories support}
107
- data = dump_values(package, keys, data)
108
-
109
- if data.key?('keywords') && is_array?(data, 'keywords')
110
- data['keywords'].sort!
111
- end
112
-
113
- if package.is_abandoned?
114
- replacement = package.replacement_package
115
- data['abandoned'] = replacement ? replacement : true
116
- end
62
+ unless package.respond_to?(:version)
63
+ raise UnexpectedValueError,
64
+ 'The package specified is missing the "version" method.'
117
65
  end
118
66
 
119
- if package.is_a?(Composer::Package::RootPackage)
120
- minimum_stability = package.minimum_stability
121
- unless minimum_stability.nil? || minimum_stability.empty?
122
- data['minimum-stability'] = minimum_stability
123
- end
124
- end
67
+ data = {}
68
+ data['name'] = package.pretty_name
69
+ data['version'] = package.pretty_version
70
+ data['version_normalized'] = package.version
125
71
 
126
- if !package.transport_options.nil? && package.transport_options.length > 0
127
- data['transport-options'] = package.transport_options
72
+ # load class specific attributes
73
+ HashDumper.attr_dumpers.each do |dumper|
74
+ if package.respond_to? dumper[:attr]
75
+ if dumper[:callback]
76
+ instance_exec package, data, &dumper[:callback]
77
+ else
78
+ attr_value = package.send dumper[:attr]
79
+ unless attr_value.nil? || attr_value.empty?
80
+ if dumper[:options][:to]
81
+ attr_key = dumper[:options][:to]
82
+ else
83
+ attr_key = dumper[:attr].to_s.tr('_', '-')
84
+ end
85
+ data[attr_key] = attr_value
86
+ end
87
+ end
88
+ end
128
89
  end
129
90
 
130
91
  data
131
92
  end
132
93
 
133
- private
94
+ require_relative 'hash_dumper/package_attribute_dumpers'
95
+ require_relative 'hash_dumper/complete_package_attribute_dumpers'
96
+ require_relative 'hash_dumper/root_package_attribute_dumpers'
134
97
 
135
- def dump_values(package, keys, data)
136
- keys.each do |method, key|
137
- key = method unless key
138
- next unless value = package.send(method)
139
- next if value.nil?
140
- next if value.is_a?(Array) && value.empty?
141
- next if value.is_a?(Hash) && value.empty?
142
- data[key] = value
143
- end
144
- data
145
- end
146
-
147
- def is_numeric?(value)
148
- true if Float(value) rescue false
149
- end
150
-
151
- def is_empty?(config, key)
152
- config.key?(key) ? config[key].empty? : true
153
- end
154
-
155
- def is_hash?(config, key)
156
- config.key?(key) ? config[key].is_a?(Hash) : false
157
- end
158
-
159
- def is_array?(config, key)
160
- config.key?(key) ? config[key].is_a?(Array) : false
161
- end
162
-
163
- def is_string?(config, key)
164
- config.key?(key) ? config[key].is_a?(String) : false
165
- end
166
98
  end
167
99
  end
168
100
  end
@@ -0,0 +1,47 @@
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 Dumper
17
+ class HashDumper
18
+
19
+ attr_dumper :scripts
20
+ attr_dumper :license
21
+ attr_dumper :authors
22
+ attr_dumper :description
23
+ attr_dumper :homepage
24
+ attr_dumper :repositories
25
+ attr_dumper :support
26
+
27
+ attr_dumper :keywords do |package, data|
28
+ keywords = package.keywords
29
+ unless keywords.nil? || keywords.empty?
30
+ data['keywords'] = keywords.is_a?(Array) ? keywords.sort! : keywords
31
+ end
32
+ end
33
+
34
+ attr_dumper :abandoned? do |package, data|
35
+ if package.abandoned?
36
+ replacement = true
37
+ if package.respond_to?(:replacement_package)
38
+ replacement = package.replacement_package
39
+ end
40
+ data['abandoned'] = replacement ? replacement : true
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,145 @@
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 Dumper
17
+ class HashDumper
18
+
19
+ attr_dumper :target_dir
20
+
21
+ attr_dumper :source_type do |package, data|
22
+ source_type = package.source_type
23
+ unless source_type.nil? || source_type.empty?
24
+
25
+ data['source'] = {}
26
+ data['source']['type'] = package.source_type
27
+
28
+ if package.respond_to? :source_url
29
+ source_url = package.source_url
30
+ unless source_url.nil? || source_url.empty?
31
+ data['source']['url'] = package.source_url
32
+ end
33
+ end
34
+
35
+ if package.respond_to? :source_reference
36
+ source_reference = package.source_reference
37
+ unless source_reference.nil? || source_reference.empty?
38
+ data['source']['reference'] = source_reference
39
+ end
40
+ end
41
+
42
+ if package.respond_to? :source_mirrors
43
+ source_mirrors = package.source_mirrors
44
+ unless source_mirrors.nil? || source_mirrors.empty?
45
+ data['source']['mirrors'] = source_mirrors
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ attr_dumper :dist_type do |package, data|
53
+ dist_type = package.dist_type
54
+ unless dist_type.nil? || dist_type.empty?
55
+
56
+ data['dist'] = {}
57
+ data['dist']['type'] = package.dist_type
58
+
59
+ if package.respond_to? :dist_url
60
+ dist_url = package.dist_url
61
+ unless dist_url.nil? || dist_url.empty?
62
+ data['dist']['url'] = package.dist_url
63
+ end
64
+ end
65
+
66
+ if package.respond_to? :dist_reference
67
+ dist_reference = package.dist_reference
68
+ unless dist_reference.nil? || dist_reference.empty?
69
+ data['dist']['reference'] = dist_reference
70
+ end
71
+ end
72
+
73
+ if package.respond_to? :dist_sha1_checksum
74
+ dist_sha1_checksum = package.dist_sha1_checksum
75
+ unless dist_sha1_checksum.nil? || dist_sha1_checksum.empty?
76
+ data['dist']['shasum'] = dist_sha1_checksum
77
+ end
78
+ end
79
+
80
+ if package.respond_to? :dist_mirrors
81
+ dist_mirrors = package.dist_mirrors
82
+ unless dist_mirrors.nil? || dist_mirrors.empty?
83
+ data['dist']['mirrors'] = dist_mirrors
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+
90
+ attr_dumper :archive_excludes do |package, data|
91
+ archive_excludes = package.archive_excludes
92
+ unless archive_excludes.nil? || archive_excludes.empty?
93
+ data['archive'] = {}
94
+ data['archive']['exclude'] = archive_excludes
95
+ end
96
+ end
97
+
98
+ ::Composer::Package::SUPPORTED_LINK_TYPES.each do |type, opts|
99
+ attr_dumper opts[:method] do |package, data|
100
+ links = package.send(opts[:method])
101
+ next if links.nil?
102
+ next if links.is_a?(Array) && links.empty?
103
+ next if links.is_a?(Hash) && links.empty?
104
+ values = links.is_a?(Hash) ? links.values : links
105
+ values.each do |link|
106
+ data[type] = {} unless data.key?(type)
107
+ data[type][link.target] = link.pretty_constraint
108
+ end
109
+ data[type].keys.sort.each do |k|
110
+ data[type][k] = data[type].delete k
111
+ end
112
+ end
113
+ end
114
+
115
+ attr_dumper :suggests do |package, data|
116
+ packages = package.suggests
117
+ unless packages.nil? || packages.empty?
118
+ packages.keys.sort.each do |k|
119
+ packages[k] = packages.delete k
120
+ end
121
+ data['suggest'] = packages
122
+ end
123
+ end
124
+
125
+ attr_dumper :release_date do |package, data|
126
+ release_date = package.release_date
127
+ unless release_date.nil?
128
+ data['time'] = release_date.strftime('%Y-%m-%d %H:%M:%S')
129
+ end
130
+ end
131
+
132
+ attr_dumper :binaries, to: 'bin'
133
+ attr_dumper :type
134
+ attr_dumper :extra
135
+ attr_dumper :installation_source
136
+ attr_dumper :autoload
137
+ attr_dumper :dev_autoload, to: 'autoload-dev'
138
+ attr_dumper :notification_url
139
+ attr_dumper :include_paths, to: 'include-path'
140
+ attr_dumper :transport_options
141
+
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,24 @@
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 Dumper
17
+ class HashDumper
18
+
19
+ attr_dumper :minimum_stability
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -18,11 +18,12 @@ module Composer
18
18
  attr_reader :source, :target, :constraint
19
19
 
20
20
  # Creates a new package link.
21
- # @param string source
22
- # @param string target
23
- # @param LinkConstraintInterface constraint Constraint applying to the target of this link
24
- # @param string description Used to create a descriptive string representation
25
- # @param string prettyConstraint
21
+ #
22
+ # @param source string
23
+ # @param target string
24
+ # @param constraint LinkConstraintInterface Constraint applying to the target of this link
25
+ # @param description string Used to create a descriptive string representation
26
+ # @param pretty_constraint string
26
27
  def initialize(source, target, constraint = nil, description = 'relates to', pretty_constraint = nil)
27
28
  @source = source.downcase
28
29
  @target = target.downcase
@@ -31,6 +32,9 @@ module Composer
31
32
  @pretty_constraint = pretty_constraint
32
33
  end
33
34
 
35
+ # Get the link's pretty constraint.
36
+ #
37
+ # @return string
34
38
  def pretty_constraint
35
39
  unless @pretty_constraint
36
40
  raise UnexpectedValueError, "Link #{self} has been misconfigured and had no pretty constraint given."
@@ -38,10 +42,16 @@ module Composer
38
42
  @pretty_constraint
39
43
  end
40
44
 
45
+ # Get the link's pretty string.
46
+ #
47
+ # @return string
41
48
  def pretty_string(source_package)
42
49
  "#{source_package.pretty_string} #{@description} #{@target} #{@constraint.pretty_string}"
43
50
  end
44
51
 
52
+ # Get the link's string representation.
53
+ #
54
+ # @return string
45
55
  def to_s
46
56
  "#{@source} #{@description} #{@target} (#{@constraint})"
47
57
  end