php-composer 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1006 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/lib/composer.rb +52 -0
- data/lib/composer/error.rb +8 -0
- data/lib/composer/json/json_file.rb +270 -0
- data/lib/composer/json/json_formatter.rb +159 -0
- data/lib/composer/json/json_validaton_error.rb +29 -0
- data/lib/composer/manager.rb +79 -0
- data/lib/composer/package/alias_package.rb +273 -0
- data/lib/composer/package/base_package.rb +130 -0
- data/lib/composer/package/complete_package.rb +55 -0
- data/lib/composer/package/dumper/hash_dumper.rb +169 -0
- data/lib/composer/package/link.rb +51 -0
- data/lib/composer/package/link_constraint/base_constraint.rb +36 -0
- data/lib/composer/package/link_constraint/empty_constraint.rb +35 -0
- data/lib/composer/package/link_constraint/multi_constraint.rb +67 -0
- data/lib/composer/package/link_constraint/specific_constraint.rb +41 -0
- data/lib/composer/package/link_constraint/version_constraint.rb +221 -0
- data/lib/composer/package/loader/hash_loader.rb +316 -0
- data/lib/composer/package/loader/json_loader.rb +47 -0
- data/lib/composer/package/loader/project_attributes_loader.rb +71 -0
- data/lib/composer/package/loader/project_root_package_loader.rb +28 -0
- data/lib/composer/package/package.rb +118 -0
- data/lib/composer/package/root_alias_package.rb +37 -0
- data/lib/composer/package/root_package.rb +37 -0
- data/lib/composer/package/version/version_parser.rb +583 -0
- data/lib/composer/package/version/version_selector.rb +106 -0
- data/lib/composer/provider.rb +94 -0
- data/lib/composer/repository/array_repository.rb +195 -0
- data/lib/composer/repository/filesystem_repository.rb +86 -0
- data/lib/composer/repository/writeable_array_repository.rb +60 -0
- data/lib/composer/version.rb +3 -0
- data/php-composer.gemspec +31 -0
- data/resources/composer-schema.json +421 -0
- metadata +188 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code file.
|
3
|
+
# Original Source: Composer\Package\CompletePackage.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
|
+
|
15
|
+
# Package containing additional metadata that is not used by the solver
|
16
|
+
class CompletePackage < Composer::Package::Package
|
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
|
25
|
+
def initialize(name, version, pretty_version)
|
26
|
+
super(name, version, pretty_version)
|
27
|
+
|
28
|
+
@license = []
|
29
|
+
@scripts = []
|
30
|
+
@support = []
|
31
|
+
@abandoned = false
|
32
|
+
end
|
33
|
+
|
34
|
+
# Determine if package is abandoned
|
35
|
+
# Return: true if package is abandoned; Otherwise false.
|
36
|
+
def is_abandoned?
|
37
|
+
@abandoned
|
38
|
+
end
|
39
|
+
|
40
|
+
# Set abandoned
|
41
|
+
# Param boolean|string $abandoned
|
42
|
+
def abandoned=(abandoned)
|
43
|
+
@abandoned = abandoned
|
44
|
+
end
|
45
|
+
|
46
|
+
# If the package is abandoned and has a suggested replacement,
|
47
|
+
# this method returns it
|
48
|
+
# @return string|nil
|
49
|
+
def replacement_package
|
50
|
+
return @abandoned.kind_of?(String) ? @abandoned : nil
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code.
|
3
|
+
# Original Source: Composer\Package\Dumper\ArrayDumper.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 Dumper
|
15
|
+
# Dumps a hash from a package
|
16
|
+
#
|
17
|
+
# PHP Authors:
|
18
|
+
# Konstantin Kudryashiv <ever.zet@gmail.com>
|
19
|
+
# Jordi Boggiano <j.boggiano@seld.be>
|
20
|
+
#
|
21
|
+
# Ruby Authors:
|
22
|
+
# Ioannis Kappas <ikappas@devworks.gr>
|
23
|
+
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
|
+
|
36
|
+
data = {}
|
37
|
+
data['name'] = package.pretty_name
|
38
|
+
data['version'] = package.pretty_version
|
39
|
+
data['version_normalized'] = package.version
|
40
|
+
|
41
|
+
if package.target_dir
|
42
|
+
data['target-dir'] = package.target_dir
|
43
|
+
end
|
44
|
+
|
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
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
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
|
65
|
+
|
66
|
+
unless package.archive_excludes.nil? || package.archive_excludes.empty?
|
67
|
+
data['archive'] = {}
|
68
|
+
data['archive']['exclude'] = package.archive_excludes
|
69
|
+
end
|
70
|
+
|
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
|
84
|
+
end
|
85
|
+
|
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
|
93
|
+
end
|
94
|
+
|
95
|
+
if package.release_date && !package.release_date.nil?
|
96
|
+
data['time'] = package.release_date.strftime('%Y-%m-%d %H:%M:%S')
|
97
|
+
end
|
98
|
+
|
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
|
117
|
+
end
|
118
|
+
|
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
|
125
|
+
|
126
|
+
if !package.transport_options.nil? && package.transport_options.length > 0
|
127
|
+
data['transport-options'] = package.transport_options
|
128
|
+
end
|
129
|
+
|
130
|
+
data
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
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
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code file.
|
3
|
+
# Original Source: Composer\Package\Link.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
|
+
|
15
|
+
# Represents a link between two packages, represented by their names
|
16
|
+
class Link
|
17
|
+
|
18
|
+
attr_reader :source, :target, :constraint
|
19
|
+
|
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
|
26
|
+
def initialize(source, target, constraint = nil, description = 'relates to', pretty_constraint = nil)
|
27
|
+
@source = source.downcase
|
28
|
+
@target = target.downcase
|
29
|
+
@constraint = constraint
|
30
|
+
@description = description
|
31
|
+
@pretty_constraint = pretty_constraint
|
32
|
+
end
|
33
|
+
|
34
|
+
def pretty_constraint
|
35
|
+
unless @pretty_constraint
|
36
|
+
raise UnexpectedValueError, "Link #{self} has been misconfigured and had no pretty constraint given."
|
37
|
+
end
|
38
|
+
@pretty_constraint
|
39
|
+
end
|
40
|
+
|
41
|
+
def pretty_string(source_package)
|
42
|
+
"#{source_package.pretty_string} #{@description} #{@target} #{@constraint.pretty_string}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
"#{@source} #{@description} #{@target} (#{@constraint})"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,36 @@
|
|
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
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -0,0 +1,67 @@
|
|
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
|
@@ -0,0 +1,41 @@
|
|
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
|