php-composer 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/Gemfile +15 -15
- data/LICENSE.txt +21 -21
- data/README.md +35 -35
- data/Rakefile +1 -1
- data/lib/composer.rb +52 -52
- data/lib/composer/error.rb +8 -8
- data/lib/composer/json/json_file.rb +270 -270
- data/lib/composer/package/alias_package.rb +273 -273
- data/lib/composer/package/base_package.rb +130 -130
- data/lib/composer/package/complete_package.rb +55 -55
- data/lib/composer/package/dumper/hash_dumper.rb +169 -169
- data/lib/composer/package/link.rb +51 -51
- data/lib/composer/package/link_constraint/base_constraint.rb +35 -35
- data/lib/composer/package/link_constraint/empty_constraint.rb +34 -34
- data/lib/composer/package/link_constraint/multi_constraint.rb +66 -66
- data/lib/composer/package/link_constraint/specific_constraint.rb +40 -40
- data/lib/composer/package/link_constraint/version_constraint.rb +220 -220
- data/lib/composer/package/loader/hash_loader.rb +316 -316
- data/lib/composer/package/loader/json_loader.rb +47 -47
- data/lib/composer/package/loader/project_attributes_loader.rb +71 -71
- data/lib/composer/package/loader/project_root_package_loader.rb +28 -28
- data/lib/composer/package/package.rb +118 -118
- data/lib/composer/package/root_alias_package.rb +37 -37
- data/lib/composer/package/root_package.rb +37 -37
- data/lib/composer/package/version/version_parser.rb +583 -583
- data/lib/composer/package/version/version_selector.rb +106 -106
- data/lib/composer/repository/filesystem_repository.rb +84 -85
- data/lib/composer/repository/{array_repository.rb → hash_repository.rb} +195 -195
- data/lib/composer/repository/{writeable_array_repository.rb → writeable_hash_repository.rb} +57 -59
- data/lib/composer/version.rb +3 -3
- data/php-composer.gemspec +31 -31
- metadata +4 -4
@@ -1,47 +1,47 @@
|
|
1
|
-
#
|
2
|
-
# This file was ported to ruby from Composer php source code.
|
3
|
-
# Original Source: Composer\Package\Loader\JsonLoader.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 Loader
|
15
|
-
|
16
|
-
# Loads a package from a json string or JsonFile
|
17
|
-
# @author Ioannis Kappas <ikappas@devworks.gr>
|
18
|
-
# @php_author Konstantin Kudryashiv <ever.zet@gmail.com>
|
19
|
-
class JsonLoader
|
20
|
-
|
21
|
-
def initialize(loader)
|
22
|
-
@loader = loader
|
23
|
-
end
|
24
|
-
|
25
|
-
# Load a json string or file
|
26
|
-
# Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from
|
27
|
-
# Returns: Composer::Package::Package
|
28
|
-
def load(json)
|
29
|
-
if json.instance_of?(Composer::Json::JsonFile)
|
30
|
-
config = json.read
|
31
|
-
elsif File.exist?(json)
|
32
|
-
config = Composer::Json::JsonFile.parse_json(
|
33
|
-
File.open(filepath, "r") { |f| f.read },
|
34
|
-
json
|
35
|
-
)
|
36
|
-
elsif json.class === "String"
|
37
|
-
config = Composer::Json::JsonFile.parse_json(
|
38
|
-
json
|
39
|
-
)
|
40
|
-
end
|
41
|
-
@loader.load(config)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code.
|
3
|
+
# Original Source: Composer\Package\Loader\JsonLoader.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 Loader
|
15
|
+
|
16
|
+
# Loads a package from a json string or JsonFile
|
17
|
+
# @author Ioannis Kappas <ikappas@devworks.gr>
|
18
|
+
# @php_author Konstantin Kudryashiv <ever.zet@gmail.com>
|
19
|
+
class JsonLoader
|
20
|
+
|
21
|
+
def initialize(loader)
|
22
|
+
@loader = loader
|
23
|
+
end
|
24
|
+
|
25
|
+
# Load a json string or file
|
26
|
+
# Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from
|
27
|
+
# Returns: Composer::Package::Package
|
28
|
+
def load(json)
|
29
|
+
if json.instance_of?(Composer::Json::JsonFile)
|
30
|
+
config = json.read
|
31
|
+
elsif File.exist?(json)
|
32
|
+
config = Composer::Json::JsonFile.parse_json(
|
33
|
+
File.open(filepath, "r") { |f| f.read },
|
34
|
+
json
|
35
|
+
)
|
36
|
+
elsif json.class === "String"
|
37
|
+
config = Composer::Json::JsonFile.parse_json(
|
38
|
+
json
|
39
|
+
)
|
40
|
+
end
|
41
|
+
@loader.load(config)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,71 +1,71 @@
|
|
1
|
-
require 'digest/crc32'
|
2
|
-
|
3
|
-
module Composer
|
4
|
-
module Package
|
5
|
-
module Loader
|
6
|
-
|
7
|
-
# Loads a package from project attributes
|
8
|
-
# @author Ioannis Kappas <ikappas@devworks.gr>
|
9
|
-
class ProjectAttributesLoader
|
10
|
-
|
11
|
-
def initialize(loader)
|
12
|
-
@loader = loader
|
13
|
-
end
|
14
|
-
|
15
|
-
# Load a json string or file
|
16
|
-
# Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from
|
17
|
-
# Returns: Composer::Package::Package
|
18
|
-
def load(project, ref, type = 'library')
|
19
|
-
|
20
|
-
version = (ref.instance_of?(Gitlab::Git::Branch)) ? "dev-#{ref.name}" : ref.name
|
21
|
-
|
22
|
-
config = {
|
23
|
-
'name' => project.path_with_namespace.gsub(/\s/, '').downcase,
|
24
|
-
'description' => project.description,
|
25
|
-
'version' => version,
|
26
|
-
'uid' => Digest::CRC32.checksum(ref.name + ref.target),
|
27
|
-
'source' => {
|
28
|
-
'url' => project.url_to_repo,
|
29
|
-
'type' => 'git',
|
30
|
-
'reference' => ref.target
|
31
|
-
},
|
32
|
-
'dist' => {
|
33
|
-
'url' => [project.web_url, 'repository', 'archive.zip?ref=' + ref.name].join('/'),
|
34
|
-
'type' => 'zip'
|
35
|
-
},
|
36
|
-
'type' => type,
|
37
|
-
'homepage' => project.web_url
|
38
|
-
}
|
39
|
-
|
40
|
-
if time = get_time(project, ref)
|
41
|
-
log("Ref: #{ref.to_json} Time: #{time}")
|
42
|
-
config['time'] = time
|
43
|
-
end
|
44
|
-
|
45
|
-
if keywords = get_keywords(project)
|
46
|
-
config['keywords'] = keywords
|
47
|
-
end
|
48
|
-
|
49
|
-
@loader.load(config)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def get_time(project, ref)
|
55
|
-
commit = project.repository.commit(ref.target)
|
56
|
-
commit.committed_date.strftime('%Y-%m-%d %H:%M:%S')
|
57
|
-
rescue
|
58
|
-
# If there's a problem, just skip the "time" field
|
59
|
-
end
|
60
|
-
|
61
|
-
def get_keywords(project)
|
62
|
-
project.tags.collect { |t| t['name'] }
|
63
|
-
end
|
64
|
-
|
65
|
-
def log(message)
|
66
|
-
Gitlab::AppLogger.error("ComposerService: #{message}")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
1
|
+
require 'digest/crc32'
|
2
|
+
|
3
|
+
module Composer
|
4
|
+
module Package
|
5
|
+
module Loader
|
6
|
+
|
7
|
+
# Loads a package from project attributes
|
8
|
+
# @author Ioannis Kappas <ikappas@devworks.gr>
|
9
|
+
class ProjectAttributesLoader
|
10
|
+
|
11
|
+
def initialize(loader)
|
12
|
+
@loader = loader
|
13
|
+
end
|
14
|
+
|
15
|
+
# Load a json string or file
|
16
|
+
# Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from
|
17
|
+
# Returns: Composer::Package::Package
|
18
|
+
def load(project, ref, type = 'library')
|
19
|
+
|
20
|
+
version = (ref.instance_of?(Gitlab::Git::Branch)) ? "dev-#{ref.name}" : ref.name
|
21
|
+
|
22
|
+
config = {
|
23
|
+
'name' => project.path_with_namespace.gsub(/\s/, '').downcase,
|
24
|
+
'description' => project.description,
|
25
|
+
'version' => version,
|
26
|
+
'uid' => Digest::CRC32.checksum(ref.name + ref.target),
|
27
|
+
'source' => {
|
28
|
+
'url' => project.url_to_repo,
|
29
|
+
'type' => 'git',
|
30
|
+
'reference' => ref.target
|
31
|
+
},
|
32
|
+
'dist' => {
|
33
|
+
'url' => [project.web_url, 'repository', 'archive.zip?ref=' + ref.name].join('/'),
|
34
|
+
'type' => 'zip'
|
35
|
+
},
|
36
|
+
'type' => type,
|
37
|
+
'homepage' => project.web_url
|
38
|
+
}
|
39
|
+
|
40
|
+
if time = get_time(project, ref)
|
41
|
+
log("Ref: #{ref.to_json} Time: #{time}")
|
42
|
+
config['time'] = time
|
43
|
+
end
|
44
|
+
|
45
|
+
if keywords = get_keywords(project)
|
46
|
+
config['keywords'] = keywords
|
47
|
+
end
|
48
|
+
|
49
|
+
@loader.load(config)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def get_time(project, ref)
|
55
|
+
commit = project.repository.commit(ref.target)
|
56
|
+
commit.committed_date.strftime('%Y-%m-%d %H:%M:%S')
|
57
|
+
rescue
|
58
|
+
# If there's a problem, just skip the "time" field
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_keywords(project)
|
62
|
+
project.tags.collect { |t| t['name'] }
|
63
|
+
end
|
64
|
+
|
65
|
+
def log(message)
|
66
|
+
Gitlab::AppLogger.error("ComposerService: #{message}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
module Composer
|
2
|
-
module Package
|
3
|
-
module Loader
|
4
|
-
|
5
|
-
# Loads a package from the project root package
|
6
|
-
# @author Ioannis Kappas <ikappas@devworks.gr>
|
7
|
-
class ProjectRootPackageLoader
|
8
|
-
|
9
|
-
def initialize(loader)
|
10
|
-
@loader = loader
|
11
|
-
end
|
12
|
-
|
13
|
-
# Load a project ref
|
14
|
-
# Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from
|
15
|
-
# Returns: Composer::Package::Package
|
16
|
-
def load(project, ref)
|
17
|
-
|
18
|
-
config = Composer::Json::JsonFile.parse_json(
|
19
|
-
project.repository.blob_at(ref.target, 'composer.json')
|
20
|
-
)
|
21
|
-
|
22
|
-
@loader.load(config)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module Composer
|
2
|
+
module Package
|
3
|
+
module Loader
|
4
|
+
|
5
|
+
# Loads a package from the project root package
|
6
|
+
# @author Ioannis Kappas <ikappas@devworks.gr>
|
7
|
+
class ProjectRootPackageLoader
|
8
|
+
|
9
|
+
def initialize(loader)
|
10
|
+
@loader = loader
|
11
|
+
end
|
12
|
+
|
13
|
+
# Load a project ref
|
14
|
+
# Param: string|JsonFile json A filename, json string or JsonFile instance to load the package from
|
15
|
+
# Returns: Composer::Package::Package
|
16
|
+
def load(project, ref)
|
17
|
+
|
18
|
+
config = Composer::Json::JsonFile.parse_json(
|
19
|
+
project.repository.blob_at(ref.target, 'composer.json')
|
20
|
+
)
|
21
|
+
|
22
|
+
@loader.load(config)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,118 +1,118 @@
|
|
1
|
-
#
|
2
|
-
# This file was ported to ruby from Composer php source code file.
|
3
|
-
# Original Source: Composer\Package\Package.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
|
-
require 'digest/crc32'
|
13
|
-
|
14
|
-
module Composer
|
15
|
-
module Package
|
16
|
-
|
17
|
-
# Core package definitions that are needed to resolve dependencies
|
18
|
-
# and install packages
|
19
|
-
class Package < Composer::Package::BasePackage
|
20
|
-
|
21
|
-
attr_reader :stability
|
22
|
-
|
23
|
-
attr_accessor :installation_source, :source_type,
|
24
|
-
:source_url, :source_reference, :source_mirrors, :dist_type,
|
25
|
-
:dist_url, :dist_reference, :dist_sha1_checksum,
|
26
|
-
:dist_mirrors, :release_date, :extra, :binaries, :requires,
|
27
|
-
:conflicts, :provides, :replaces, :dev_requires, :suggests,
|
28
|
-
:autoload, :dev_autoload, :include_paths, :archive_excludes,
|
29
|
-
:notification_url
|
30
|
-
|
31
|
-
# complete package attributes
|
32
|
-
|
33
|
-
|
34
|
-
# Creates a new in memory package.
|
35
|
-
# Param: string name The package's name
|
36
|
-
# Param: string version The package's version
|
37
|
-
# Param: string prettyVersion The package's non-normalized version
|
38
|
-
def initialize(name, version, pretty_version)
|
39
|
-
super(name)
|
40
|
-
|
41
|
-
# default values
|
42
|
-
@extra = {}
|
43
|
-
@binaries = []
|
44
|
-
@requires = {}
|
45
|
-
@conflicts = {}
|
46
|
-
@provides = {}
|
47
|
-
@replaces = {}
|
48
|
-
@dev_requires = {}
|
49
|
-
@suggests = {}
|
50
|
-
@autoload = {}
|
51
|
-
@dev_autoload = {}
|
52
|
-
@include_paths = []
|
53
|
-
@archive_excludes = []
|
54
|
-
|
55
|
-
# init package attributes
|
56
|
-
replace_version(version, pretty_version)
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
def attributes
|
61
|
-
dumper = Composer::Package::Dumper::HashDumper.new
|
62
|
-
dumper.dump(self)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Set package type
|
66
|
-
# Param: string type
|
67
|
-
def type=(type)
|
68
|
-
@type = type
|
69
|
-
end
|
70
|
-
|
71
|
-
# Get package type
|
72
|
-
# Return: string
|
73
|
-
def type
|
74
|
-
@type ? @type : 'library'
|
75
|
-
end
|
76
|
-
|
77
|
-
def target_dir=(target_dir)
|
78
|
-
@target_dir = target_dir
|
79
|
-
end
|
80
|
-
|
81
|
-
def target_dir
|
82
|
-
return unless @target_dir
|
83
|
-
regex = '(?:^|[\\\\/]+)\.\.?(?:[\\\\/]+|$)(?:\.\.?(?:[\\\\/]+|$))*'
|
84
|
-
@target_dir.gsub(/#{regex}/x, '/').gsub(/^\/+/, '')
|
85
|
-
end
|
86
|
-
|
87
|
-
# Returns package unique name, constructed from name, version and
|
88
|
-
# release type.
|
89
|
-
# Return: string
|
90
|
-
def unique_name
|
91
|
-
"#{name}-#{version}"
|
92
|
-
end
|
93
|
-
|
94
|
-
def pretty_string
|
95
|
-
"#{pretty_name} #{pretty_version}"
|
96
|
-
end
|
97
|
-
|
98
|
-
# Determine if development package
|
99
|
-
# Return: true if development package; Otherwise false.
|
100
|
-
def is_dev
|
101
|
-
@dev
|
102
|
-
end
|
103
|
-
|
104
|
-
# Replaces current version and pretty version with passed values.
|
105
|
-
# It also sets stability.
|
106
|
-
# Param: string version The package's normalized version
|
107
|
-
# Param: string prettyVersion The package's non-normalized version
|
108
|
-
def replace_version(version, pretty_version)
|
109
|
-
@version = version
|
110
|
-
@pretty_version = pretty_version
|
111
|
-
|
112
|
-
@stability = Composer::Package::Version::VersionParser::parse_stability(version)
|
113
|
-
@dev = @stability === 'dev'
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code file.
|
3
|
+
# Original Source: Composer\Package\Package.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
|
+
require 'digest/crc32'
|
13
|
+
|
14
|
+
module Composer
|
15
|
+
module Package
|
16
|
+
|
17
|
+
# Core package definitions that are needed to resolve dependencies
|
18
|
+
# and install packages
|
19
|
+
class Package < Composer::Package::BasePackage
|
20
|
+
|
21
|
+
attr_reader :stability
|
22
|
+
|
23
|
+
attr_accessor :installation_source, :source_type,
|
24
|
+
:source_url, :source_reference, :source_mirrors, :dist_type,
|
25
|
+
:dist_url, :dist_reference, :dist_sha1_checksum,
|
26
|
+
:dist_mirrors, :release_date, :extra, :binaries, :requires,
|
27
|
+
:conflicts, :provides, :replaces, :dev_requires, :suggests,
|
28
|
+
:autoload, :dev_autoload, :include_paths, :archive_excludes,
|
29
|
+
:notification_url
|
30
|
+
|
31
|
+
# complete package attributes
|
32
|
+
|
33
|
+
|
34
|
+
# Creates a new in memory package.
|
35
|
+
# Param: string name The package's name
|
36
|
+
# Param: string version The package's version
|
37
|
+
# Param: string prettyVersion The package's non-normalized version
|
38
|
+
def initialize(name, version, pretty_version)
|
39
|
+
super(name)
|
40
|
+
|
41
|
+
# default values
|
42
|
+
@extra = {}
|
43
|
+
@binaries = []
|
44
|
+
@requires = {}
|
45
|
+
@conflicts = {}
|
46
|
+
@provides = {}
|
47
|
+
@replaces = {}
|
48
|
+
@dev_requires = {}
|
49
|
+
@suggests = {}
|
50
|
+
@autoload = {}
|
51
|
+
@dev_autoload = {}
|
52
|
+
@include_paths = []
|
53
|
+
@archive_excludes = []
|
54
|
+
|
55
|
+
# init package attributes
|
56
|
+
replace_version(version, pretty_version)
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def attributes
|
61
|
+
dumper = Composer::Package::Dumper::HashDumper.new
|
62
|
+
dumper.dump(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Set package type
|
66
|
+
# Param: string type
|
67
|
+
def type=(type)
|
68
|
+
@type = type
|
69
|
+
end
|
70
|
+
|
71
|
+
# Get package type
|
72
|
+
# Return: string
|
73
|
+
def type
|
74
|
+
@type ? @type : 'library'
|
75
|
+
end
|
76
|
+
|
77
|
+
def target_dir=(target_dir)
|
78
|
+
@target_dir = target_dir
|
79
|
+
end
|
80
|
+
|
81
|
+
def target_dir
|
82
|
+
return unless @target_dir
|
83
|
+
regex = '(?:^|[\\\\/]+)\.\.?(?:[\\\\/]+|$)(?:\.\.?(?:[\\\\/]+|$))*'
|
84
|
+
@target_dir.gsub(/#{regex}/x, '/').gsub(/^\/+/, '')
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns package unique name, constructed from name, version and
|
88
|
+
# release type.
|
89
|
+
# Return: string
|
90
|
+
def unique_name
|
91
|
+
"#{name}-#{version}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def pretty_string
|
95
|
+
"#{pretty_name} #{pretty_version}"
|
96
|
+
end
|
97
|
+
|
98
|
+
# Determine if development package
|
99
|
+
# Return: true if development package; Otherwise false.
|
100
|
+
def is_dev
|
101
|
+
@dev
|
102
|
+
end
|
103
|
+
|
104
|
+
# Replaces current version and pretty version with passed values.
|
105
|
+
# It also sets stability.
|
106
|
+
# Param: string version The package's normalized version
|
107
|
+
# Param: string prettyVersion The package's non-normalized version
|
108
|
+
def replace_version(version, pretty_version)
|
109
|
+
@version = version
|
110
|
+
@pretty_version = pretty_version
|
111
|
+
|
112
|
+
@stability = Composer::Package::Version::VersionParser::parse_stability(version)
|
113
|
+
@dev = @stability === 'dev'
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|