php-composer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,29 @@
|
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code file.
|
3
|
+
# Original Source: Composer\Json\JsonValidationException.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 Json
|
14
|
+
# Represents a Json Validation error
|
15
|
+
#
|
16
|
+
# PHP Authors:
|
17
|
+
# Jordi Boggiano <j.boggiano@seld.be>
|
18
|
+
#
|
19
|
+
# Ruby Authors:
|
20
|
+
# Ioannis Kappas <ikappas@devworks.gr>
|
21
|
+
class JsonValidationError < StandardError
|
22
|
+
attr_reader :errors
|
23
|
+
|
24
|
+
def initialize(errors)
|
25
|
+
@errors = errors
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module Composer
|
4
|
+
class Manager
|
5
|
+
|
6
|
+
BLANK_REPOSITORY = { "packages"=>[],"includes"=>{} }
|
7
|
+
|
8
|
+
def initialize(project)
|
9
|
+
@project = project
|
10
|
+
@provider = Composer::Provider.new(project)
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_package(package)
|
14
|
+
|
15
|
+
raise ArgumentError, 'package must be specified' unless package
|
16
|
+
# raise TypeError, 'package must be a class of Composer::Package::Package or superclass' unless package.kind_of?(Composer::Package::Package)
|
17
|
+
|
18
|
+
@provider.add_package(package)
|
19
|
+
@provider.save_or_delete
|
20
|
+
|
21
|
+
update_repository
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def rm_package(package)
|
26
|
+
|
27
|
+
raise ArgumentError, 'package must be specified' unless package
|
28
|
+
# raise TypeError, 'package must be a class of Composer::Package::Package or superclass' unless package.kind_of?(Composer::Package::Package)
|
29
|
+
|
30
|
+
@provider.rm_package(package)
|
31
|
+
@provider.save_or_delete
|
32
|
+
|
33
|
+
update_repository
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def clear_packages
|
38
|
+
|
39
|
+
@provider.clear_packages
|
40
|
+
@provider.save_or_delete
|
41
|
+
|
42
|
+
update_repository
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def update_repository
|
49
|
+
|
50
|
+
# load packages.json
|
51
|
+
if File.exist?(packages_json_file)
|
52
|
+
File.open(packages_json_file, "w") do |file|
|
53
|
+
file.write(BLANK_REPOSITORY.to_json)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
includes = File.open(packages_json_file, "r") { |f| ActiveSupport::JSON.decode(f.read)["includes"] }
|
58
|
+
includes ||= {}
|
59
|
+
|
60
|
+
# process provider
|
61
|
+
name = "/p/#{@provider.filename}"
|
62
|
+
if @provider.has_packages?
|
63
|
+
includes[name] ||= {}
|
64
|
+
includes[name]["sha1"] = @provider.sha1
|
65
|
+
else
|
66
|
+
includes.delete(name)
|
67
|
+
end
|
68
|
+
|
69
|
+
# update packages.json
|
70
|
+
content = { "packages"=>[],"includes"=>includes }.to_json
|
71
|
+
File.open(packages_json_file, "w") { |f| f.write(content) }
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def packages_json_file
|
76
|
+
File.join(Rails.public_path, "/packages.json")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,273 @@
|
|
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
|
+
|
15
|
+
# The root package represents the project's composer.json
|
16
|
+
# and contains additional metadata
|
17
|
+
# @php_author Jordi Boggiano <j.boggiano@seld.be>
|
18
|
+
# @author Ioannis Kappas <ikappas@devworks.gr>
|
19
|
+
class AliasPackage < Composer::Package::BasePackage
|
20
|
+
|
21
|
+
attr_reader :alias_of, :requires, :conflicts, :provides, :replaces
|
22
|
+
:dev_requires
|
23
|
+
|
24
|
+
attr_accessor :repositories, :license, :keywords, :authors,
|
25
|
+
:description, :homepage, :scripts, :support,
|
26
|
+
:source_url, :source_reference, :source_mirrors
|
27
|
+
|
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
|
32
|
+
def initialize(alias_of, version, pretty_version)
|
33
|
+
super(alias_of.name)
|
34
|
+
|
35
|
+
@version = version
|
36
|
+
@pretty_version = pretty_version
|
37
|
+
@alias_of = alias_of
|
38
|
+
@stability = Composer::Package::Version::VersionParser::parse_stability(version)
|
39
|
+
@dev = @stability === 'dev'
|
40
|
+
|
41
|
+
# 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
|
61
|
+
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
|
+
end
|
87
|
+
|
88
|
+
# Determine if development package
|
89
|
+
# Return: true if development package; Otherwise false.
|
90
|
+
def is_dev
|
91
|
+
@dev
|
92
|
+
end
|
93
|
+
|
94
|
+
# Stores whether this is an alias created by an aliasing in the requirements of the root package or not
|
95
|
+
# Use by the policy for sorting manually aliased packages first, see #576
|
96
|
+
# @param bool $value
|
97
|
+
# @return mixed
|
98
|
+
def root_package_alias=(value)
|
99
|
+
@root_package_alias = value
|
100
|
+
end
|
101
|
+
|
102
|
+
# @see setRootPackageAlias
|
103
|
+
# @return bool
|
104
|
+
def is_root_package_alias
|
105
|
+
@root_package_alias
|
106
|
+
end
|
107
|
+
|
108
|
+
#######################################
|
109
|
+
# Wrappers around the aliased package #
|
110
|
+
#######################################
|
111
|
+
|
112
|
+
def type
|
113
|
+
@alias_of.Type
|
114
|
+
end
|
115
|
+
|
116
|
+
def target_dir
|
117
|
+
@alias_of.target_dir
|
118
|
+
end
|
119
|
+
|
120
|
+
def extra
|
121
|
+
@alias_of.extra
|
122
|
+
end
|
123
|
+
|
124
|
+
def installation_source=(type)
|
125
|
+
@alias_of.installation_source = type
|
126
|
+
end
|
127
|
+
|
128
|
+
def installation_source
|
129
|
+
@alias_of.installation_source
|
130
|
+
end
|
131
|
+
|
132
|
+
def source_type
|
133
|
+
@alias_of.source_type
|
134
|
+
end
|
135
|
+
|
136
|
+
def source_url
|
137
|
+
@alias_of.source_url
|
138
|
+
end
|
139
|
+
|
140
|
+
def source_urls
|
141
|
+
@alias_of.source_urls
|
142
|
+
end
|
143
|
+
|
144
|
+
def source_reference=(reference)
|
145
|
+
@alias_of.source_reference = reference
|
146
|
+
end
|
147
|
+
|
148
|
+
def source_reference
|
149
|
+
@alias_of.source_reference
|
150
|
+
end
|
151
|
+
|
152
|
+
def source_mirrors=(mirrors)
|
153
|
+
@alias_of.source_mirrors = mirrors
|
154
|
+
end
|
155
|
+
|
156
|
+
def source_mirrors
|
157
|
+
@alias_of.SourceMirrors
|
158
|
+
end
|
159
|
+
|
160
|
+
def dist_type
|
161
|
+
@alias_of.dist_type
|
162
|
+
end
|
163
|
+
|
164
|
+
def dist_url
|
165
|
+
@alias_of.dist_url
|
166
|
+
end
|
167
|
+
|
168
|
+
def dist_urls
|
169
|
+
@alias_of.dist_urls
|
170
|
+
end
|
171
|
+
|
172
|
+
def dist_reference
|
173
|
+
@alias_of.dist_reference
|
174
|
+
end
|
175
|
+
|
176
|
+
def dist_reference=(reference)
|
177
|
+
@alias_of.dist_reference = reference
|
178
|
+
end
|
179
|
+
|
180
|
+
def dist_sha1_checksum
|
181
|
+
@alias_of.dist_sha1_checksum
|
182
|
+
end
|
183
|
+
|
184
|
+
def transport_options=(options)
|
185
|
+
@alias_of.transport_options = options
|
186
|
+
end
|
187
|
+
|
188
|
+
def transport_options
|
189
|
+
@alias_of.transport_options
|
190
|
+
end
|
191
|
+
|
192
|
+
def dist_mirrors=(mirrors)
|
193
|
+
@alias_of.dist_mirrors = mirrors
|
194
|
+
end
|
195
|
+
|
196
|
+
def dist_mirrors
|
197
|
+
@alias_of.dist_mirrors
|
198
|
+
end
|
199
|
+
|
200
|
+
def scripts
|
201
|
+
@alias_of.scripts
|
202
|
+
end
|
203
|
+
|
204
|
+
def license
|
205
|
+
@alias_of.license
|
206
|
+
end
|
207
|
+
|
208
|
+
def autoload
|
209
|
+
@alias_of.autoload
|
210
|
+
end
|
211
|
+
|
212
|
+
def dev_autoload
|
213
|
+
@alias_of.dev_autoload
|
214
|
+
end
|
215
|
+
|
216
|
+
def include_paths
|
217
|
+
@alias_of.include_paths
|
218
|
+
end
|
219
|
+
|
220
|
+
def repositories
|
221
|
+
@alias_of.repositories
|
222
|
+
end
|
223
|
+
|
224
|
+
def release_date
|
225
|
+
@alias_of.release_date
|
226
|
+
end
|
227
|
+
|
228
|
+
def binaries
|
229
|
+
@alias_of.binaries
|
230
|
+
end
|
231
|
+
|
232
|
+
def keywords
|
233
|
+
@alias_of.keywords
|
234
|
+
end
|
235
|
+
|
236
|
+
def description
|
237
|
+
@alias_of.description
|
238
|
+
end
|
239
|
+
|
240
|
+
def homepage
|
241
|
+
@alias_of.homepage
|
242
|
+
end
|
243
|
+
|
244
|
+
def suggests
|
245
|
+
@alias_of.suggests
|
246
|
+
end
|
247
|
+
|
248
|
+
def authors
|
249
|
+
@alias_of.authors
|
250
|
+
end
|
251
|
+
|
252
|
+
def support
|
253
|
+
@alias_of.support
|
254
|
+
end
|
255
|
+
|
256
|
+
def notification_url
|
257
|
+
@alias_of.notification_url
|
258
|
+
end
|
259
|
+
|
260
|
+
def archive_excludes
|
261
|
+
@alias_of.archive_excludes
|
262
|
+
end
|
263
|
+
|
264
|
+
def is_abandoned
|
265
|
+
@alias_of.is_abandoned
|
266
|
+
end
|
267
|
+
|
268
|
+
def replacement_package
|
269
|
+
@alias_of.replacement_package
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code.
|
3
|
+
# Original Source: Composer\Package\BasePackage.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
|
+
# Base class for packages providing name storage
|
16
|
+
# and default match implementation
|
17
|
+
# @php_author Nils Adermann <naderman@naderman.de>
|
18
|
+
# @author Ioannis Kappas <ikappas@devworks.gr>
|
19
|
+
class BasePackage
|
20
|
+
|
21
|
+
# base package attributes
|
22
|
+
attr_accessor :id, :repository, :transport_options
|
23
|
+
attr_reader :name, :pretty_name, :version, :pretty_version, :stability
|
24
|
+
|
25
|
+
STABILITY_STABLE = 0
|
26
|
+
STABILITY_RC = 5
|
27
|
+
STABILITY_BETA = 10
|
28
|
+
STABILITY_ALPHA = 15
|
29
|
+
STABILITY_DEV = 20
|
30
|
+
|
31
|
+
SUPPORTED_LINK_TYPES = {
|
32
|
+
'require' => {
|
33
|
+
'description' => 'requires',
|
34
|
+
'method' => 'requires'
|
35
|
+
},
|
36
|
+
'conflict' => {
|
37
|
+
'description' => 'conflicts',
|
38
|
+
'method' => 'conflicts'
|
39
|
+
},
|
40
|
+
'provide' => {
|
41
|
+
'description' => 'provides',
|
42
|
+
'method' => 'provides'
|
43
|
+
},
|
44
|
+
'replace' => {
|
45
|
+
'description' => 'replaces',
|
46
|
+
'method' => 'replaces'
|
47
|
+
},
|
48
|
+
'require-dev' => {
|
49
|
+
'description' => 'requires (for development)',
|
50
|
+
'method' => 'dev_requires'
|
51
|
+
}
|
52
|
+
}.freeze()
|
53
|
+
|
54
|
+
class << self
|
55
|
+
|
56
|
+
def stabilities
|
57
|
+
@stabilities ||= {
|
58
|
+
'stable' => STABILITY_STABLE,
|
59
|
+
'RC' => STABILITY_RC,
|
60
|
+
'beta' => STABILITY_BETA,
|
61
|
+
'alpha' => STABILITY_ALPHA,
|
62
|
+
'dev' => STABILITY_DEV,
|
63
|
+
}.freeze()
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
# Creates a new in memory package.
|
69
|
+
# Param: string name The package's name
|
70
|
+
# Param: string version The package's version
|
71
|
+
# Param: string pretty_version The package's non-normalized version
|
72
|
+
def initialize(name)
|
73
|
+
@pretty_name = name
|
74
|
+
@name = name.downcase
|
75
|
+
@id = -1
|
76
|
+
@transport_options = []
|
77
|
+
end
|
78
|
+
|
79
|
+
def attributes
|
80
|
+
dumper = Composer::Package::Dumper::HashDumper.new
|
81
|
+
dumper.dump(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Set package type
|
85
|
+
# Param: string type
|
86
|
+
def type=(type)
|
87
|
+
@type = type
|
88
|
+
end
|
89
|
+
|
90
|
+
# Get package type
|
91
|
+
# Return: string
|
92
|
+
def type
|
93
|
+
@type ? @type : 'library'
|
94
|
+
end
|
95
|
+
|
96
|
+
# Set package repository
|
97
|
+
def repository=(repository)
|
98
|
+
if (@repository && repository != @repository)
|
99
|
+
raise LogicError, 'A package can only be added to one repository'
|
100
|
+
end
|
101
|
+
@repository = repository
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get package repository
|
105
|
+
def repository
|
106
|
+
@repository
|
107
|
+
end
|
108
|
+
|
109
|
+
# def is_platform?
|
110
|
+
# @repository && @repository.instance_of?(PlatformRepository)
|
111
|
+
# end
|
112
|
+
|
113
|
+
# Returns package unique name, constructed from name, version and
|
114
|
+
# release type.
|
115
|
+
# Return: string
|
116
|
+
def unique_name
|
117
|
+
"#{name}-#{version}"
|
118
|
+
end
|
119
|
+
|
120
|
+
def pretty_string
|
121
|
+
"#{pretty_name} #{pretty_version}"
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_s
|
125
|
+
unique_name
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|