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.
- checksums.yaml +4 -4
- data/.rbenv-gemsets +1 -0
- data/.rubocop.yml +131 -188
- data/.ruby-version +1 -0
- data/Gemfile +0 -9
- data/Rakefile +11 -0
- data/lib/composer.rb +52 -49
- data/lib/composer/json/json_file.rb +110 -83
- data/lib/composer/json/json_formatter.rb +43 -77
- data/lib/composer/json/{json_validaton_error.rb → json_validation_error.rb} +6 -2
- data/lib/composer/package/alias_package.rb +77 -61
- data/lib/composer/package/complete_package.rb +88 -18
- data/lib/composer/package/dumper/hash_dumper.rb +50 -118
- data/lib/composer/package/dumper/hash_dumper/complete_package_attribute_dumpers.rb +47 -0
- data/lib/composer/package/dumper/hash_dumper/package_attribute_dumpers.rb +145 -0
- data/lib/composer/package/dumper/hash_dumper/root_package_attribute_dumpers.rb +24 -0
- data/lib/composer/package/link.rb +15 -5
- data/lib/composer/package/loader/hash_loader.rb +92 -228
- data/lib/composer/package/loader/hash_loader/complete_package_attribute_loaders.rb +83 -0
- data/lib/composer/package/loader/hash_loader/package_attribute_loaders.rb +181 -0
- data/lib/composer/package/loader/hash_loader/root_package_attribute_loaders.rb +32 -0
- data/lib/composer/package/loader/json_loader.rb +7 -9
- data/lib/composer/package/package.rb +611 -43
- data/lib/composer/package/root_alias_package.rb +186 -15
- data/lib/composer/package/root_package.rb +12 -4
- data/lib/composer/package/version/version_parser.rb +16 -532
- data/lib/composer/package/version/version_selector.rb +127 -68
- data/lib/composer/repository/base_repository.rb +46 -3
- data/lib/composer/repository/composite_repository.rb +4 -4
- data/lib/composer/repository/filesystem_repository.rb +15 -8
- data/lib/composer/repository/hash_repository.rb +62 -45
- data/lib/composer/repository/writeable_hash_repository.rb +5 -5
- data/lib/composer/util/composer_mirror.rb +76 -0
- data/php-composer.gemspec +14 -8
- data/resources/composer-schema.json +12 -0
- metadata +117 -16
- data/lib/composer/error.rb +0 -8
- data/lib/composer/package/base_package.rb +0 -130
- data/lib/composer/package/link_constraint/base_constraint.rb +0 -36
- data/lib/composer/package/link_constraint/empty_constraint.rb +0 -35
- data/lib/composer/package/link_constraint/multi_constraint.rb +0 -67
- data/lib/composer/package/link_constraint/specific_constraint.rb +0 -41
- data/lib/composer/package/link_constraint/version_constraint.rb +0 -221
- 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
|
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
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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?
|
245
|
-
|
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
|
-
|
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
|
-
|
267
|
-
#
|
136
|
+
##
|
137
|
+
# Retrieves a branch alias if it exists.
|
268
138
|
#
|
269
|
-
#
|
270
|
-
# +config+ array The entire package config
|
139
|
+
# i.e.(dev-master => 1.0.x-dev)
|
271
140
|
#
|
272
|
-
#
|
273
|
-
#
|
274
|
-
#
|
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
|
-
|
277
|
-
(config['
|
278
|
-
|
279
|
-
|
280
|
-
|
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
|
-
|
287
|
-
|
288
|
-
|
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
|
-
|
291
|
-
|
158
|
+
# ensure that it is the current branch aliasing itself
|
159
|
+
next if config['version'].downcase != source_branch.downcase
|
292
160
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
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
|
-
|
166
|
+
return validated_target_branch
|
167
|
+
end
|
168
|
+
end
|
299
169
|
end
|
300
170
|
nil
|
301
171
|
end
|
302
172
|
|
303
|
-
|
304
|
-
|
305
|
-
|
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
|