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,36 +0,0 @@
1
- #
2
- # This file was ported to ruby from Composer php source code file.
3
- # Original Source: Composer\Package\AliasPackage.php
4
- #
5
- # (c) Nils Adermann <naderman@naderman.de>
6
- # Jordi Boggiano <j.boggiano@seld.be>
7
- #
8
- # For the full copyright and license information, please view the LICENSE
9
- # file that was distributed with this source code.
10
- #
11
-
12
- module Composer
13
- module Package
14
- module LinkConstraint
15
- class BaseConstraint
16
-
17
- def matches(provider)
18
- raise NotImplementedError
19
- end
20
-
21
- def pretty_string=(pretty_string)
22
- raise NotImplementedError
23
- end
24
-
25
- def pretty_string
26
- raise NotImplementedError
27
- end
28
-
29
- def to_s
30
- raise NotImplementedError
31
- end
32
-
33
- end
34
- end
35
- end
36
- end
@@ -1,35 +0,0 @@
1
- #
2
- # This file was ported to ruby from Composer php source code file.
3
- # Original Source: Composer\Package\AliasPackage.php
4
- #
5
- # (c) Nils Adermann <naderman@naderman.de>
6
- # Jordi Boggiano <j.boggiano@seld.be>
7
- #
8
- # For the full copyright and license information, please view the LICENSE
9
- # file that was distributed with this source code.
10
- #
11
-
12
- module Composer
13
- module Package
14
- module LinkConstraint
15
- class EmptyConstraint < BaseConstraint
16
- def matches(provider)
17
- true
18
- end
19
-
20
- def pretty_string=(pretty_string)
21
- @pretty_string = pretty_string
22
- end
23
-
24
- def pretty_string
25
- return to_s unless @pretty_string
26
- @pretty_string
27
- end
28
-
29
- def to_s
30
- '[]'
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,67 +0,0 @@
1
- #
2
- # This file was ported to ruby from Composer php source code file.
3
- # Original Source: Composer\Package\AliasPackage.php
4
- #
5
- # (c) Nils Adermann <naderman@naderman.de>
6
- # Jordi Boggiano <j.boggiano@seld.be>
7
- #
8
- # For the full copyright and license information, please view the LICENSE
9
- # file that was distributed with this source code.
10
- #
11
-
12
- module Composer
13
- module Package
14
- module LinkConstraint
15
- class MultiConstraint < BaseConstraint
16
- # Sets operator and version to compare a package with
17
- # @param array $constraints A set of constraints
18
- # @param bool $conjunctive Whether the constraints should be treated as conjunctive or disjunctive
19
- def initialize(constraints, conjunctive = true)
20
- @constraints = constraints
21
- @conjunctive = conjunctive
22
- end
23
-
24
- def matches(provider)
25
- if @conjunctive === false
26
- @constraints.each do |constraint|
27
- if constraint.matches(provider)
28
- return true
29
- end
30
- end
31
- return false
32
- end
33
-
34
- @constraints.each do |constraint|
35
- if !constraint.matches(provider)
36
- return false
37
- end
38
- end
39
-
40
- true
41
- end
42
-
43
- def pretty_string=(pretty_string)
44
- @pretty_string = pretty_string
45
- end
46
-
47
- def pretty_string
48
- return to_s unless @pretty_string
49
- @pretty_string
50
- end
51
-
52
- def to_s
53
- constraints = []
54
- @constraints.each do |constraint|
55
- if constraint.is_a?(Array)
56
- constraints << String(constraint[0])
57
- else
58
- constraints << String(constraint)
59
- end
60
- end
61
- separator = @conjunctive ? ' ' : ' || '
62
- "[#{constraints.join(separator)}]"
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,41 +0,0 @@
1
- #
2
- # This file was ported to ruby from Composer php source code file.
3
- # Original Source: Composer\Package\AliasPackage.php
4
- #
5
- # (c) Nils Adermann <naderman@naderman.de>
6
- # Jordi Boggiano <j.boggiano@seld.be>
7
- #
8
- # For the full copyright and license information, please view the LICENSE
9
- # file that was distributed with this source code.
10
- #
11
-
12
- module Composer
13
- module Package
14
- module LinkConstraint
15
- class SpecificConstraint < BaseConstraint
16
-
17
- def matches(provider)
18
-
19
- if provider.is_a?(MultiConstraint)
20
- # turn matching around to find a match
21
- return provider.matches(self)
22
- elsif provider.is_a?(SpecificConstraint)
23
- return match_specific(provider)
24
- end
25
-
26
- true
27
- end
28
-
29
- def pretty_string=(pretty_string)
30
- @prettyString = pretty_string
31
- end
32
-
33
- def pretty_string
34
- return to_s unless @pretty_string
35
- @pretty_string
36
- end
37
-
38
- end
39
- end
40
- end
41
- end
@@ -1,221 +0,0 @@
1
- #
2
- # This file was ported to ruby from Composer php source code file.
3
- # Original Source: Composer\Package\LinkConstraint\VersionConstraint.php
4
- #
5
- # (c) Nils Adermann <naderman@naderman.de>
6
- # Jordi Boggiano <j.boggiano@seld.be>
7
- #
8
- # For the full copyright and license information, please view the LICENSE
9
- # file that was distributed with this source code.
10
- #
11
-
12
- module Composer
13
- module Package
14
- module LinkConstraint
15
- class VersionConstraint < SpecificConstraint
16
- attr_reader :operator, :version
17
-
18
- @@cache = nil
19
-
20
- # Sets operator and version to compare a package with
21
- # @param string $operator A comparison operator
22
- # @param string $version A version to compare to
23
- def initialize(operator, version)
24
- if operator === '='
25
- operator = '=='
26
- end
27
-
28
- if operator === '<>'
29
- operator = '!='
30
- end
31
-
32
- @operator = operator
33
- @version = version
34
- end
35
-
36
- def version_compare(a, b, operator, compare_branches = false)
37
-
38
- a_is_branch = 'dev-' === a[0...4]
39
- b_is_branch = 'dev-' === b[0...4]
40
- if a_is_branch && b_is_branch
41
- return operator == '==' && a === b
42
- end
43
-
44
- # when branches are not comparable, we make sure dev branches never match anything
45
- if !compare_branches && (a_is_branch || b_is_branch)
46
- return false
47
- end
48
-
49
- # Standardise versions
50
- ver_a = a.strip.gsub(/([\-?\_?\+?])/, '.').gsub(/([^0-9\.]+)/, '.$1.').gsub(/\.\./, '.').split('.')
51
- ver_b = b.strip.gsub(/([\-?\_?\+?])/, '.').gsub(/([^0-9\.]+)/, '.$1.').gsub(/\.\./, '.').split('.')
52
-
53
- # Replace empty entries at the start of the array
54
- while ver_a[0] && ver_a[0].empty?
55
- ver_a.shift
56
- end
57
- while ver_b[0] && ver_b[0].empty?
58
- ver_b.shift
59
- end
60
-
61
- # Release state order
62
- # '#' stands for any number
63
- versions = {
64
- 'dev' => 0,
65
- 'alpha' => 1,
66
- 'a' => 1,
67
- 'beta' => 2,
68
- 'b' => 2,
69
- 'RC' => 3,
70
- '#' => 4,
71
- 'p' => 5,
72
- 'pl' => 5
73
- }
74
-
75
- # Loop through each segment in the version string
76
- compare = 0
77
- for i in 0..([ver_a.length, ver_b.length].min - 1)
78
- # for (i = 0, $x = [ver_a.length, ver_b.length].min; i < $x; i++) {
79
-
80
- next if ver_a[i] == ver_b[i]
81
-
82
- i1 = ver_a[i]
83
- i2 = ver_b[i]
84
-
85
- i1_is_numeric = true if Float(i1) rescue false
86
- i2_is_numeric = true if Float(i2) rescue false
87
-
88
- if i1_is_numeric && i2_is_numeric
89
- compare = (i1 < i2) ? -1 : 1
90
- break
91
- end
92
-
93
- # We use the position of '#' in the versions list
94
- # for numbers... (so take care of # in original string)
95
- if i1 == '#'
96
- i1 = ''
97
- elsif i1_is_numeric
98
- i1 = '#';
99
- end
100
-
101
- if i2 == '#'
102
- i2 = ''
103
- elsif i2_is_numeric
104
- i2 = '#'
105
- end
106
-
107
- if !versions[i1].nil? && versions[i2].nil?
108
- compare = versions[i1] < versions[i2] ? -1 : 1
109
- elsif !versions[i1].nil?
110
- compare = 1;
111
- elsif !versions[i2].nil?
112
- compare = -1;
113
- else
114
- compare = 0;
115
- end
116
-
117
- break;
118
-
119
- end
120
-
121
- # If previous loop didn't find anything, compare the "extra" segments
122
- if compare == 0
123
- if ver_b.length > ver_a.length
124
- if !ver_b[i].nil && !versions[ver_b[i]].nil
125
- compare = (versions[ver_b[i]] < 4) ? 1 : -1;
126
- else
127
- compare = -1;
128
- end
129
- elsif ver_b.length < ver_a.length
130
- if !ver_a[i].nil && !versions[ver_a[i]].nil
131
- compare = (versions[ver_a[i]] < 4) ? -1 : 1;
132
- else
133
- compare = 1;
134
- end
135
- end
136
- end
137
-
138
- # Compare the versions
139
- case operator
140
- when '>', 'gt'
141
- return compare > 0
142
- when '>=', 'ge'
143
- return compare >= 0
144
- when '<=', 'le'
145
- return compare <= 0
146
- when '==', '=', 'eq'
147
- return compare == 0
148
- when '<>', '!=', 'ne'
149
- return compare != 0
150
- when '', '<', 'lt'
151
- return compare < 0
152
- end
153
-
154
- false
155
- end
156
-
157
- # @param VersionConstraint provider
158
- # @param bool compare_branches
159
- # @return bool
160
- def match_specific(provider, compare_branches = false)
161
- @@cache = {} unless @@cache
162
- @@cache[@operator] = {} unless @@cache.key?(@operator)
163
- @@cache[@operator][@version] = {} unless @@cache[@operator].key?(@version)
164
- @@cache[@operator][@version][provider.operator] = {} unless @@cache[@operator][@version].key?(provider.operator)
165
- @@cache[@operator][@version][provider.operator][provider.version] = {} unless @@cache[@operator][@version][provider.operator].key?(provider.version)
166
-
167
- if @@cache[@operator][@version][provider.operator][provider.version].key?(compare_branches)
168
- return @@cache[@operator][@version][provider.operator][provider.version][compare_branches]
169
- end
170
-
171
- (@@cache[@operator][@version][provider.operator][provider.version][compare_branches] = do_match_specific(provider, compare_branches))
172
- end
173
-
174
- def to_s
175
- "#{@operator} #{@version}"
176
- end
177
-
178
- private
179
-
180
- # /**
181
- # * @param VersionConstraint provider
182
- # * @param bool compare_branches
183
- # * @return bool
184
- def do_match_specific(provider, compare_branches = false)
185
- self_op_ne = @operator.gsub('=', '')
186
- provider_op_ne = provider.operator.gsub('=', '')
187
-
188
- self_op_is_eq = '==' === @operator
189
- self_op_is_ne = '!=' === @operator
190
- provider_op_is_eq = '==' === provider.operator
191
- provider_op_is_ne = '!=' === provider.operator
192
-
193
- # '!=' operator is match when other operator is not '==' operator or version is not match
194
- # these kinds of comparisons always have a solution
195
- if self_op_is_ne || provider_op_is_ne
196
- return !self_op_is_eq && !provider_op_is_eq ||
197
- version_compare(provider.version, @version, '!=', compare_branches)
198
- end
199
-
200
- # an example for the condition is <= 2.0 & < 1.0
201
- # these kinds of comparisons always have a solution
202
- if @operator != '==' && self_op_ne == provider_op_ne
203
- return true
204
- end
205
-
206
- if version_compare(provider.version, @version, @operator, compare_branches)
207
- # special case, e.g. require >= 1.0 and provide < 1.0
208
- # 1.0 >= 1.0 but 1.0 is outside of the provided interval
209
- if provider.version == @version && provider.operator == provider_op_ne && @operator != self_op_ne
210
- return false
211
- end
212
-
213
- return true
214
- end
215
-
216
- false
217
- end
218
- end
219
- end
220
- end
221
- end
@@ -1,3 +0,0 @@
1
- module Composer
2
- VERSION = '0.4.5'
3
- end