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 file.
3
+ #
3
4
  # Original Source: Composer\Json\JsonFormatter.php
5
+ # Ref SHA: ce085826711a6354024203c6530ee0b56fea9c13
4
6
  #
5
7
  # (c) Nils Adermann <naderman@naderman.de>
6
8
  # Jordi Boggiano <j.boggiano@seld.be>
@@ -9,18 +11,9 @@
9
11
  # file that was distributed with this source code.
10
12
  #
11
13
 
12
- # JSON_HEX_TAG => 1
13
- # JSON_HEX_AMP => 2
14
- # JSON_HEX_APOS => 4
15
- # JSON_HEX_QUOT => 8
16
- # JSON_FORCE_OBJECT => 16
17
- # JSON_NUMERIC_CHECK => 32
18
- # JSON_UNESCAPED_SLASHES => 64
19
- # JSON_PRETTY_PRINT => 128
20
- # JSON_UNESCAPED_UNICODE => 256
21
-
22
14
  module Composer
23
15
  module Json
16
+
24
17
  # * Formats json strings used for php < 5.4 because the json_encode doesn't
25
18
  # * supports the flags JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
26
19
  # * in these versions
@@ -33,27 +26,18 @@ module Composer
33
26
  # Ioannis Kappas <ikappas@devworks.gr>
34
27
  class JsonFormatter
35
28
 
36
- JSON_HEX_TAG = 1
37
- JSON_HEX_AMP = 2
38
- JSON_HEX_APOS = 4
39
- JSON_HEX_QUOT = 8
40
- JSON_FORCE_OBJECT = 16
41
- JSON_NUMERIC_CHECK = 32
42
- JSON_UNESCAPED_SLASHES = 64
43
- JSON_PRETTY_PRINT = 128
44
- JSON_UNESCAPED_UNICODE = 256
45
-
46
29
  class << self
30
+
47
31
  # This code is based on the function found at:
48
32
  # http://recursive-design.com/blog/2008/03/11/format-json-with-php/
49
33
  #
50
34
  # Originally licensed under MIT by Dave Perrett <mail@recursive-design.com>
51
35
  #
52
36
  # @param json string
53
- # @param unescape_unicode bool Un escape unicode
54
- # @param unescape_slashes bool Un escape slashes
37
+ # @param unescape_unicode bool Whether to unescape unicode
38
+ # @param unescape_slashes bool Whether to unescape slashes
55
39
  # @return string
56
- def format(json, options)
40
+ def format(json, unescape_unicode, unescape_slashes)
57
41
 
58
42
  result = ''
59
43
  pos = 0
@@ -63,14 +47,14 @@ module Composer
63
47
  out_of_quotes = true
64
48
  buffer = ''
65
49
  no_escape = true
66
-
50
+
67
51
  for i in 0..(str_len - 1)
68
52
 
69
- # Grab the next character in the string
53
+ # grab the next character in the string
70
54
  char = json[i]
71
55
 
72
- # Are we inside a quoted string?
73
- if '"' === char && no_escape
56
+ # are we inside a quoted string?
57
+ if char === '"' && no_escape
74
58
  out_of_quotes = !out_of_quotes
75
59
  end
76
60
 
@@ -78,79 +62,61 @@ module Composer
78
62
  buffer << char
79
63
  no_escape = '\\' === char ? !no_escape : true
80
64
  next
81
- elsif buffer != ''
82
- if options & JSON_HEX_TAG === JSON_HEX_TAG
83
- buffer.gsub!('<', '\\u003C')
84
- buffer.gsub!('>', '\\u003E')
85
- end
86
- if options & JSON_HEX_AMP === JSON_HEX_AMP
87
- buffer.gsub!('&', '\\u0026')
88
- end
89
- if options & JSON_HEX_APOS === JSON_HEX_APOS
90
- buffer.gsub!('\'', '\\u0027')
91
- end
92
- if options & JSON_HEX_QUOT === JSON_HEX_QUOT
93
- buffer.gsub!('\"', '\\u0022')
94
- end
95
- if options & JSON_UNESCAPED_SLASHES === JSON_UNESCAPED_SLASHES
65
+
66
+ elsif !buffer.empty?
67
+
68
+ if unescape_slashes
96
69
  buffer.gsub!('\\/', '/')
97
70
  end
98
- if options & JSON_UNESCAPED_UNICODE === JSON_UNESCAPED_UNICODE
71
+
72
+ if unescape_unicode
99
73
  buffer.gsub!(/\\u([\da-fA-F]{4})/) {|m| [$1].pack('H*').unpack('n*').pack('U*')}
100
74
  end
101
75
 
102
76
  result << buffer + char
103
77
  buffer = ''
104
78
  next
79
+
105
80
  end
106
81
 
107
- if options & JSON_PRETTY_PRINT === JSON_PRETTY_PRINT
108
- if char === ':'
82
+ if char === ':'
109
83
  # Add a space after the : character
110
84
  char << ' '
111
- elsif char === '}' || char === ']'
112
- pos -= 1
113
- prev_char = json[i - 1] #substr(json, i - 1, 1)
114
-
115
- if prev_char != '{' && prev_char != '['
116
- # If this character is the end of an element,
117
- # output a new line and indent the next line
118
- result << new_line
119
-
120
- for j in 0..(pos - 1)
121
- result << indent_str
122
- end
123
- else
124
- # Collapse empty {} and []
125
- result.rstrip!
126
- end
127
- end
128
- end
129
85
 
130
- result << char
86
+ elsif char === '}' || char === ']'
87
+
88
+ pos -= 1
89
+ prev_char = json[i - 1]
131
90
 
132
- if options & JSON_PRETTY_PRINT === JSON_PRETTY_PRINT
133
- # If the last character was the beginning of an element,
134
- # output a new line and indent the next line
135
- if char === ',' || char === '{' || char === '['
91
+ if prev_char != '{' && prev_char != '['
92
+ # If this character is the end of an element,
93
+ # output a new line and indent the next line
136
94
  result << new_line
137
- pos += 1 if char === '{' || char === '['
95
+
138
96
  for j in 0..(pos - 1)
139
97
  result << indent_str
140
98
  end
99
+ else
100
+ # Collapse empty {} and []
101
+ result.rstrip!
141
102
  end
142
103
  end
143
- end
144
104
 
145
- result
146
- end
105
+ result << char
147
106
 
148
- def unescape_slashes(s)
149
- s.gsub('\\/', '/')
150
- end
107
+ # If the last character was the beginning of an element,
108
+ # output a new line and indent the next line
109
+ if char === ',' || char === '{' || char === '['
110
+ result << new_line
111
+ pos += 1 if char === '{' || char === '['
112
+ for j in 0..(pos - 1)
113
+ result << indent_str
114
+ end
115
+ end
151
116
 
152
- def unescape_unicode(s)
153
- s.gsub(/\\u([\da-fA-F]{4})/) {|m| [$1].pack('H*').unpack('n*').pack('U*')}
117
+ end
118
+
119
+ result
154
120
  end
155
121
 
156
122
  end
@@ -1,6 +1,8 @@
1
1
  #
2
2
  # This file was ported to ruby from Composer php source code file.
3
+ #
3
4
  # Original Source: Composer\Json\JsonValidationException.php
5
+ # Ref SHA: 16578d1d01656ce7b694abd5517af44395cc53b3
4
6
  #
5
7
  # (c) Nils Adermann <naderman@naderman.de>
6
8
  # Jordi Boggiano <j.boggiano@seld.be>
@@ -11,6 +13,7 @@
11
13
 
12
14
  module Composer
13
15
  module Json
16
+
14
17
  # Represents a Json Validation error
15
18
  #
16
19
  # PHP Authors:
@@ -18,12 +21,13 @@ module Composer
18
21
  #
19
22
  # Ruby Authors:
20
23
  # Ioannis Kappas <ikappas@devworks.gr>
21
- class JsonValidationError < StandardError
24
+ class JsonValidationError < ::Composer::Error
22
25
  attr_reader :errors
23
26
 
24
27
  def initialize(errors)
25
28
  @errors = errors
26
29
  end
27
30
  end
31
+
28
32
  end
29
- end
33
+ end
@@ -9,6 +9,8 @@
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
 
@@ -16,84 +18,53 @@ module Composer
16
18
  # and contains additional metadata
17
19
  # @php_author Jordi Boggiano <j.boggiano@seld.be>
18
20
  # @author Ioannis Kappas <ikappas@devworks.gr>
19
- class AliasPackage < Composer::Package::BasePackage
21
+ class AliasPackage < ::Composer::Package::CompletePackage
20
22
 
21
- attr_reader :alias_of, :requires, :conflicts, :provides, :replaces
22
- :dev_requires
23
+ attr_reader :alias_of, :requires, :conflicts, :provides, :replaces, :dev_requires
23
24
 
24
- attr_accessor :repositories, :license, :keywords, :authors,
25
- :description, :homepage, :scripts, :support,
26
- :source_url, :source_reference, :source_mirrors
25
+ # attr_accessor :repositories, :license, :keywords, :authors,
26
+ # :description, :homepage, :scripts, :support,
27
+ # :source_url, :source_reference, :source_mirrors
27
28
 
28
- # All descendants' constructors should call this parent constructor
29
- # @param alias_of Package The package this package is an alias of
30
- # @param version String The version the alias must report
31
- # @param pretty_version String The alias's non-normalized version
29
+ # All descendants' constructors should call this parent constructor.
30
+ #
31
+ # Params:
32
+ # +alias_of+:: the package this package is an alias of
33
+ # +version+:: the version the alias must report
34
+ # +pretty_version+:: the alias's non-normalized version
32
35
  def initialize(alias_of, version, pretty_version)
33
- super(alias_of.name)
36
+
37
+ unless alias_of.kind_of?(::Composer::Package::Package)
38
+ raise ::Composer::ArgumentError,
39
+ 'Invalid alias_of argument supplied.'
40
+ end
41
+
42
+ super(alias_of.name, version, pretty_version)
34
43
 
35
44
  @version = version
36
45
  @pretty_version = pretty_version
37
46
  @alias_of = alias_of
38
- @stability = Composer::Package::Version::VersionParser::parse_stability(version)
47
+ @stability = ::Composer::Semver::VersionParser::parse_stability(version)
39
48
  @dev = @stability === 'dev'
40
49
 
41
50
  # replace self.version dependencies
42
- %w{requires dev_requires}.each do |type|
43
-
44
- links = alias_of.send(type)
45
- links.each do |index, link|
46
- # link is self.version, but must be replacing also the replaced version
47
- if 'self.version' === link.pretty_constraint
48
- links[index] = Composer::Package::Link.new(
49
- link.source,
50
- link.target,
51
- Composer::Package::LinkConstraint::VersionConstraint.new(
52
- '=',
53
- @version
54
- ),
55
- type,
56
- pretty_version
57
- )
58
- end
59
- end
60
- @type = links
51
+ %w{requires dev_requires conflicts provides replaces}.each do |type|
52
+ links = alias_of.send type
53
+ @type = replace_self_version_dependencies links, type
61
54
  end
62
-
63
- # duplicate self.version provides
64
- %w{conflicts provides replaces}.each do |type|
65
- links = alias_of.send(type)
66
- new_links = []
67
- links.each do |link|
68
- # link is self.version, but must be replacing also the replaced version
69
- if 'self.version' === link.pretty_constraint
70
- new_links = Composer.Package.Link.new(
71
- link.source,
72
- link.target,
73
- Composer::Package::LinkConstraint.VersionConstraint.new(
74
- '=',
75
- @version
76
- ),
77
- type,
78
- pretty_version
79
- )
80
- end
81
- end
82
- @type = links.zip(new_links).flatten.compact
83
- # @type = (links << new_links)
84
- end
85
-
86
55
  end
87
56
 
88
57
  # Determine if development package
89
58
  # Return: true if development package; Otherwise false.
90
- def is_dev
59
+ def is_dev?
91
60
  @dev
92
61
  end
93
62
 
94
63
  # Stores whether this is an alias created by an aliasing in the requirements of the root package or not
95
64
  # Use by the policy for sorting manually aliased packages first, see #576
96
- # @param bool $value
65
+ #
66
+ # Params:
67
+ # +value+:: bool $value
97
68
  # @return mixed
98
69
  def root_package_alias=(value)
99
70
  @root_package_alias = value
@@ -110,7 +81,7 @@ module Composer
110
81
  #######################################
111
82
 
112
83
  def type
113
- @alias_of.Type
84
+ @alias_of.type
114
85
  end
115
86
 
116
87
  def target_dir
@@ -154,7 +125,7 @@ module Composer
154
125
  end
155
126
 
156
127
  def source_mirrors
157
- @alias_of.SourceMirrors
128
+ @alias_of.source_mirrors
158
129
  end
159
130
 
160
131
  def dist_type
@@ -261,13 +232,58 @@ module Composer
261
232
  @alias_of.archive_excludes
262
233
  end
263
234
 
264
- def is_abandoned?
265
- @alias_of.is_abandoned?
235
+ def abandoned?
236
+ @alias_of.abandoned?
266
237
  end
267
238
 
268
239
  def replacement_package
269
240
  @alias_of.replacement_package
270
241
  end
242
+
243
+ protected
244
+
245
+ ##
246
+ # Replace self version dependencies helper
247
+ #
248
+ # @param links array
249
+ # An array of links
250
+ # @param link_type
251
+ # The specified links type
252
+ #
253
+ # @return array
254
+ ##
255
+ def replace_self_version_dependencies(links, link_type)
256
+ if %w{conflicts provides replaces}.include? link_type
257
+ new_links = []
258
+ links.each do |link|
259
+ # link is self.version, but must be replacing also the replaced version
260
+ if 'self.version' === link.pretty_constraint
261
+ new_links = ::Composer.Package.Link.new(
262
+ link.source,
263
+ link.target,
264
+ ::Composer::Semver::Constraint::Constraint.new('=', @version),
265
+ type,
266
+ pretty_version
267
+ )
268
+ end
269
+ end
270
+ links = links.zip(new_links).flatten.compact
271
+ else
272
+ links.each do |index, link|
273
+ # link is self.version, but must be replacing also the replaced version
274
+ if 'self.version' === link.pretty_constraint
275
+ links[index] = ::Composer::Package::Link.new(
276
+ link.source,
277
+ link.target,
278
+ ::Composer::Semver::Constraint::Constraint.new('=', @version),
279
+ type,
280
+ pretty_version
281
+ )
282
+ end
283
+ end
284
+ end
285
+ links
286
+ end
271
287
  end
272
288
  end
273
289
  end
@@ -12,42 +12,112 @@
12
12
  module Composer
13
13
  module Package
14
14
 
15
- # Package containing additional metadata that is not used by the solver
16
- class CompletePackage < Composer::Package::Package
15
+ # Represents a package containing additional metadata that is not used by the solver.
16
+ class CompletePackage < ::Composer::Package::Package
17
17
 
18
- attr_accessor :scripts, :repositories, :license, :keywords, :authors,
19
- :description, :homepage, :support
20
-
21
- # Creates a new in memory package.
22
- # Param: string name The package's name
23
- # Param: string version The package's version
24
- # Param: string prettyVersion The package's non-normalized version
18
+ # Creates a new in memory complete package.
19
+ #
20
+ # Params:
21
+ # +name+:: The package's name.
22
+ # +version+:: The package's version.
23
+ # +pretty_version+:: The package's non-normalized version.
25
24
  def initialize(name, version, pretty_version)
26
25
  super(name, version, pretty_version)
27
-
28
- @license = []
29
26
  @scripts = []
27
+ @repositories = nil
28
+ @license = []
29
+ @keywords = nil
30
+ @authors = nil
31
+ @description = nil
32
+ @homepage = nil
30
33
  @support = []
31
34
  @abandoned = false
32
35
  end
33
36
 
34
- # Determine if package is abandoned
35
- # Return: true if package is abandoned; Otherwise false.
36
- def is_abandoned?
37
- @abandoned
37
+ attr_writer :scripts
38
+
39
+ # Returns the scripts of this package
40
+ # @return array array('script name' => array('listeners'))
41
+ attr_reader :scripts
42
+
43
+ # Set the repositories
44
+ # @param repositories array
45
+ attr_writer :repositories
46
+
47
+ # Returns an array of repositories
48
+ #
49
+ # {"<type>": {<config key/values>}}
50
+ #
51
+ # @return array Repositories
52
+ attr_reader :repositories
53
+
54
+ # Set the license
55
+ # @param license array
56
+ attr_writer :license
57
+
58
+ # Returns the package license, e.g. MIT, BSD, GPL
59
+ # @return array The package licenses
60
+ attr_reader :license
61
+
62
+ # Set the keywords
63
+ # @param keywords array
64
+ attr_writer :keywords
65
+
66
+ # Returns an array of keywords relating to the package
67
+ # @return array
68
+ attr_reader :keywords
69
+
70
+ # Set the authors
71
+ # @param authors array
72
+ attr_writer :authors
73
+
74
+ # Returns an array of authors of the package
75
+ # Each item can contain name/homepage/email keys
76
+ #
77
+ # @return array
78
+ attr_reader :authors
79
+
80
+ # Set the description
81
+ # @param description string
82
+ attr_writer :description
83
+
84
+ # Returns the package description
85
+ # @return string
86
+ attr_reader :description
87
+
88
+ # Set the homepage
89
+ # @param homepage string
90
+ attr_writer :homepage
91
+
92
+ # Returns the package homepage
93
+ # @return string
94
+ attr_reader :homepage
95
+
96
+ # Set the support information
97
+ # @param support array
98
+ attr_writer :support
99
+
100
+ # Returns the support information
101
+ # @return array
102
+ attr_reader :support
103
+
104
+ # Determine whether the package is abandoned.
105
+ # @return bool true if package is abandoned; Otherwise false.
106
+ def abandoned?
107
+ @abandoned.kind_of?(String) ? true : @abandoned === true
38
108
  end
39
109
 
40
110
  # Set abandoned
41
- # Param boolean|string $abandoned
111
+ # @param abandoned bool
42
112
  def abandoned=(abandoned)
43
113
  @abandoned = abandoned
44
114
  end
45
115
 
46
116
  # If the package is abandoned and has a suggested replacement,
47
- # this method returns it
117
+ # this method returns it.
48
118
  # @return string|nil
49
119
  def replacement_package
50
- return @abandoned.kind_of?(String) ? @abandoned : nil
120
+ @abandoned.kind_of?(String) ? @abandoned : nil
51
121
  end
52
122
 
53
123
  end