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
@@ -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\ArrayLoader.php
5
+ # Ref SHA: a1427d7fd626d4308c190a267dd7a993f87c6a2a
4
6
  #
5
7
  # (c) Nils Adermann <naderman@naderman.de>
6
8
  # Jordi Boggiano <j.boggiano@seld.be>
@@ -9,9 +11,13 @@
9
11
  # file that was distributed with this source code.
10
12
  #
11
13
 
14
+ require 'composer/semver'
15
+
12
16
  module Composer
13
17
  module Package
14
18
  module Loader
19
+
20
+ ##
15
21
  # Loads a package from a hash
16
22
  #
17
23
  # PHP Authors:
@@ -20,14 +26,41 @@ module Composer
20
26
  #
21
27
  # Ruby Authors:
22
28
  # Ioannis Kappas <ikappas@devworks.gr>
29
+ ##
23
30
  class HashLoader
31
+
32
+ class << self
33
+
34
+ def attr_loaders
35
+ @attr_loaders ||= []
36
+ end
37
+
38
+ def attr_loader( attr, options = {}, &block)
39
+ if block_given?
40
+ attr_loaders.push({ attr: attr, options: options, callback: block })
41
+ else
42
+ attr_loaders.push({ attr: attr, options: options })
43
+ end
44
+ end
45
+
46
+ end
47
+
24
48
  def initialize(parser = nil, load_options = false)
25
- parser = Composer::Package::Version::VersionParser.new unless parser
49
+ parser ||= ::Composer::Semver::VersionParser.new
50
+
51
+ unless parser.kind_of? (::Composer::Semver::VersionParser)
52
+ raise ArgumentError,
53
+ 'Invalid parser supplied.'
54
+ end
55
+
26
56
  @version_parser = parser
27
57
  @load_options = load_options
58
+
28
59
  end
29
60
 
30
61
  def load(config, class_name = 'Composer::Package::CompletePackage')
62
+
63
+ # verify supplied arguments
31
64
  unless config
32
65
  raise ArgumentError,
33
66
  'Invalid package configuration supplied.'
@@ -50,210 +83,47 @@ module Composer
50
83
  version = @version_parser.normalize(config['version'])
51
84
  end
52
85
 
86
+ # create the package based on the class specified
53
87
  package = Object.const_get(class_name).new(
54
88
  config['name'],
55
89
  version,
56
90
  config['version']
57
91
  )
58
92
 
59
- # parse type
60
- if config.key?('type')
61
- package.type = config['type'].downcase
62
- else
63
- package.type = 'library'
64
- end
65
-
66
- # parse target-dir
67
- if config.key?('target-dir')
68
- package.target_dir = config['target-dir']
69
- end
70
-
71
- # parse extra
72
- if config.key?('extra') && config['extra'].is_a?(Hash)
73
- package.extra = config['extra']
74
- end
75
-
76
- # parse bin
77
- if config.key?('bin')
78
- unless config['bin'].is_a?(Array)
79
- raise UnexpectedValueError,
80
- "Package #{config['name']}'s bin key should be an hash, \
81
- #{config['bin'].class.name} given."
82
- end
83
- config['bin'].each do |bin|
84
- bin.gsub!(/^\/+/, '')
85
- end
86
- package.binaries = config['bin']
87
- end
88
-
89
- # parse installation source
90
- if config.key?('installation-source')
91
- package.installation_source = config['installation-source']
92
- end
93
-
94
- # parse source
95
- if config.key?('source')
96
- if [:type, :url, :reference].all? {|k| config['source'].key? k}
97
- raise UnexpectedValueError,
98
- "Package #{config['name']}'s source key should be \
99
- specified as \
100
- {\"type\": ..., \"url\": ..., \"reference\": ...}, \n
101
- #{config['source'].to_json} given."
102
- end
103
- package.source_type = config['source']['type']
104
- package.source_url = config['source']['url']
105
- package.source_reference = config['source']['reference']
106
- if config['source'].key?('mirrors')
107
- package.source_mirrors = config['source']['mirrors']
108
- end
109
- end
110
-
111
- #parse dist
112
- if config.key?('dist')
113
- if [:type, :url].all? {|k| config['dist'].key? k}
114
- raise UnexpectedValueError,
115
- "Package #{config['name']}'s dist key should be \
116
- specified as \
117
- {\"type\": ..., \"url\": ..., \"reference\": ..., \"shasum\": ...},\n
118
- #{config['dist'].to_json} given."
119
- end
120
- package.dist_type = config['dist']['type']
121
- package.dist_url = config['dist']['url']
122
-
123
- package.dist_reference = config['dist'].key?('reference') ?
124
- config['dist']['reference'] : nil
125
-
126
- package.dist_sha1_checksum = config['dist'].key?('shasum') ?
127
- config['dist']['shasum'] : nil
128
-
129
- if config['dist'].key?('mirrors')
130
- package.dist_mirrors = config['dist']['mirrors']
131
- end
132
- end
133
-
134
- # parse supported link types
135
- Composer::Package::BasePackage::SUPPORTED_LINK_TYPES.each do |type, opts|
136
- next if !config.key?(type)
137
- package.send(
138
- "#{opts['method']}=",
139
- @version_parser.parse_links(
140
- package.name,
141
- package.pretty_version,
142
- opts['description'],
143
- config[type]
144
- )
145
- )
146
- end
147
-
148
- # parse suggest
149
- if config.key?('suggest') && config['suggest'].is_a?(Hash)
150
- config['suggest'].each do |target, reason|
151
- if 'self.version' === reason.strip!
152
- config['suggest'][target] = package.pretty_version
153
- end
154
- end
155
- package.suggests = config['suggest']
156
- end
157
-
158
- # parse autoload
159
- if config.key? 'autoload'
160
- package.autoload = config['autoload']
161
- end
162
-
163
- # parse autoload-dev
164
- if config.key? 'autoload-dev'
165
- package.dev_autoload = config['autoload-dev']
166
- end
167
-
168
- # parse include-path
169
- if config.key? 'include-path'
170
- package.include_paths = config['include-path']
171
- end
172
-
173
- # parse time
174
- if !is_empty?(config, 'time')
175
- time = is_numeric?(config['time']) ? "@#{config['time']}" : config['time']
176
- begin
177
- date = Time.zone.parse(time)
178
- package.release_date = date
179
- rescue Exception => e
180
- log("Time Exception #{e}")
181
- end
182
- end
183
-
184
- # parse notification url
185
- if !is_empty?(config, 'notification-url')
186
- package.notification_url = config['notification-url']
187
- end
188
-
189
- # parse archive excludes
190
- if config.key?('archive') &&
191
- config['archive'].key?('exclude') &&
192
- !config['archive']['exclude'].empty?
193
- package.archive_excludes = config['archive']['exclude']
194
- end
195
-
196
- if package.instance_of?(Composer::Package::CompletePackage)
197
-
198
- # parse scripts
199
- if config.key?('scripts') && config['scripts'].is_a?(Array)
200
- config['scripts'].each do |event, listeners|
201
- config['scripts'][event] = Array(listeners)
93
+ # load class specific attributes
94
+ HashLoader.attr_loaders.each do |loader|
95
+ package_attr = "#{loader[:attr]}="
96
+ if package.respond_to? package_attr
97
+ if loader[:callback]
98
+ instance_exec config, package, &loader[:callback]
99
+ else
100
+ if loader[:options][:from]
101
+ config_key = loader[:options][:from]
102
+ else
103
+ config_key = loader[:attr].to_s.tr('_', '-')
104
+ end
105
+
106
+ if config.key? config_key
107
+ config_value = config[config_key]
108
+ unless config_value.nil? || config_value.empty?
109
+ package.send package_attr, config_value
110
+ end
111
+ end
202
112
  end
203
- package.scripts = config['scripts']
204
- end
205
-
206
- # parse description
207
- if !is_empty?(config, 'description') && config['description'].is_a?(String)
208
- package.description = config['description']
209
113
  end
210
-
211
- # parse homepage
212
- if !is_empty?(config, 'homepage') && config['homepage'].is_a?(String)
213
- package.homepage = config['homepage']
214
- end
215
-
216
- # parse keywords
217
- if !is_empty?(config, 'keywords') && config['keywords'].is_a?(Array)
218
- package.keywords = config['keywords']
219
- end
220
-
221
- # parse license
222
- if !is_empty?(config, 'license')
223
- package.license = config['license'].is_a?(Array) ? config['license'] : [config['license']]
224
- end
225
-
226
- # parse authors
227
- if !is_empty?(config, 'authors') && config['authors'].is_a?(Array)
228
- package.authors = config['authors']
229
- end
230
-
231
- # parse support
232
- if config.key?('support')
233
- package.support = config['support']
234
- end
235
-
236
- # parse abandoned
237
- if config.key?('abandoned')
238
- package.abandoned = config['abandoned']
239
- end
240
-
241
114
  end
242
115
 
243
- if alias_normalized = get_branch_alias(config)
244
- if package.instance_of?(Composer::Package::RootPackage)
245
- package = Composer::Package::RootAliasPackage.new(
246
- package,
247
- alias_normalized,
248
- alias_normalized.gsub(/(\.9{7})+/, '.x')
249
- )
116
+ if (alias_normalized = get_branch_alias(config))
117
+ if package.instance_of? ::Composer::Package::RootPackage
118
+ alias_class = 'RootAliasPackage'
250
119
  else
251
- package = Composer::Package::AliasPackage.new(
252
- package,
253
- alias_normalized,
254
- alias_normalized.gsub(/(\.9{7})+/, '.x')
255
- )
120
+ alias_class = 'AliasPackage'
256
121
  end
122
+ package = Object.const_get("::Composer::Package::#{alias_class}").new(
123
+ package,
124
+ alias_normalized,
125
+ alias_normalized.gsub(/(\.9{7})+/, '.x')
126
+ )
257
127
  end
258
128
 
259
129
  if @load_options && config.key?('transport-options')
@@ -263,52 +133,46 @@ module Composer
263
133
  package
264
134
  end
265
135
 
266
- # Retrieves a branch alias
267
- # (dev-master => 1.0.x-dev for example) if it exists
136
+ ##
137
+ # Retrieves a branch alias if it exists.
268
138
  #
269
- # Params:
270
- # +config+ array The entire package config
139
+ # i.e.(dev-master => 1.0.x-dev)
271
140
  #
272
- # Returns:
273
- # string|nil normalized version of the branch alias
274
- # or null if there is none
141
+ # @param config array
142
+ # The entire package config
143
+ #
144
+ # @return string|nil
145
+ # The normalized version of the branch alias or nil if there is none.
146
+ ##
275
147
  def get_branch_alias(config)
276
- return nil unless
277
- (config['version'].start_with?('dev-') || config['version'].end_with?('-dev')) &&
278
- config.key?('extra') &&
279
- config['extra'].key?('branch-alias') &&
280
- config['extra']['branch-alias'].is_a?(Hash)
281
-
282
- config['extra']['branch-alias'].each do |source_branch, target_branch|
283
- # ensure it is an alias to a -dev package
284
- next if !target_branch.end_with?('-dev')
148
+ if config.key?('version') && (config['version'].start_with?('dev-') || config['version'].end_with?('-dev'))
149
+ if config.key?('extra') && config['extra'].key?('branch-alias') && config['extra']['branch-alias'].is_a?(Hash)
150
+ config['extra']['branch-alias'].each do |source_branch, target_branch|
151
+ # ensure it is an alias to a -dev package
152
+ next unless target_branch.end_with?('-dev')
285
153
 
286
- # normalize without -dev and ensure it's a numeric branch that is parseable
287
- validated_target_branch = @version_parser.normalize_branch(target_branch[0..-5])
288
- next if !validated_target_branch.end_with?('-dev')
154
+ # normalize without -dev and ensure it's a numeric branch that is parseable
155
+ validated_target_branch = @version_parser.normalize_branch(target_branch[0..-5])
156
+ next unless validated_target_branch.end_with?('-dev')
289
157
 
290
- # ensure that it is the current branch aliasing itself
291
- next if config['version'].downcase != source_branch.downcase
158
+ # ensure that it is the current branch aliasing itself
159
+ next if config['version'].downcase != source_branch.downcase
292
160
 
293
- # If using numeric aliases ensure the alias is a valid subversion
294
- source_prefix = @version_parser.parse_numeric_alias_prefix(source_branch)
295
- target_prefix = @version_parser.parse_numeric_alias_prefix(target_branch)
296
- next if source_prefix && target_prefix && target_prefix.index(source_prefix) != 0 #(stripos($targetPrefix, $sourcePrefix) !== 0)
161
+ # If using numeric aliases ensure the alias is a valid subversion
162
+ source_prefix = @version_parser.parse_numeric_alias_prefix(source_branch)
163
+ target_prefix = @version_parser.parse_numeric_alias_prefix(target_branch)
164
+ next if source_prefix && target_prefix && target_prefix.index(source_prefix) != 0 #(stripos($targetPrefix, sourcePrefix) !== 0)
297
165
 
298
- return validated_target_branch
166
+ return validated_target_branch
167
+ end
168
+ end
299
169
  end
300
170
  nil
301
171
  end
302
172
 
303
- private
304
-
305
- def is_numeric?(value)
306
- true if Float(value) rescue false
307
- end
308
-
309
- def is_empty?(config, key)
310
- config.key?(key) ? config[key].empty? : true
311
- end
173
+ require_relative 'hash_loader/package_attribute_loaders'
174
+ require_relative 'hash_loader/complete_package_attribute_loaders'
175
+ require_relative 'hash_loader/root_package_attribute_loaders'
312
176
 
313
177
  end
314
178
  end
@@ -0,0 +1,83 @@
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 :scripts do |config, package|
20
+ if config.key?('scripts') && config['scripts'].is_a?(Array)
21
+ config['scripts'].each do |event, listeners|
22
+ config['scripts'][event] = Array(listeners)
23
+ end
24
+ package.scripts = config['scripts']
25
+ end
26
+ end
27
+
28
+ attr_loader :description do |config, package|
29
+ if config.key?('description') && config['description'].is_a?(String)
30
+ unless config['description'].empty?
31
+ package.description = config['description']
32
+ end
33
+ end
34
+ end
35
+
36
+ attr_loader :homepage do |config, package|
37
+ if config.key?('homepage') && config['homepage'].is_a?(String)
38
+ unless config['homepage'].empty?
39
+ package.homepage = config['homepage']
40
+ end
41
+ end
42
+ end
43
+
44
+ attr_loader :keywords do |config, package|
45
+ if config.key?('keywords') && config['keywords'].is_a?(Array)
46
+ unless config['keywords'].empty?
47
+ package.keywords = config['keywords']
48
+ end
49
+ end
50
+ end
51
+
52
+ attr_loader :license do |config, package|
53
+ if config.key?('license')
54
+ unless config['license'].empty?
55
+ package.license = config['license'].is_a?(Array) ? config['license'] : [config['license']]
56
+ end
57
+ end
58
+ end
59
+
60
+ attr_loader :authors do |config, package|
61
+ if config.key?('authors') && config['authors'].is_a?(Array)
62
+ unless config['authors'].empty?
63
+ package.authors = config['authors']
64
+ end
65
+ end
66
+ end
67
+
68
+ attr_loader :support do |config, package|
69
+ if config.key?('support')
70
+ package.support = config['support']
71
+ end
72
+ end
73
+
74
+ attr_loader :abandoned do |config, package|
75
+ if config.key?('abandoned')
76
+ package.abandoned = config['abandoned']
77
+ end
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end