berkshelf 2.0.18 → 3.0.0.beta1
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.
- data/.ruby-version +1 -1
- data/.travis.yml +4 -1
- data/CHANGELOG.md +2 -26
- data/Gemfile +12 -2
- data/README.md +9 -1
- data/berkshelf.gemspec +9 -18
- data/bin/berks +3 -13
- data/features/apply_command.feature +11 -9
- data/features/berksfile.feature +8 -10
- data/features/config.feature +1 -2
- data/features/configure_command.feature +13 -14
- data/features/contingent_command.feature +13 -1
- data/features/cookbook_command.feature +2 -4
- data/features/groups_install.feature +10 -2
- data/features/help.feature +1 -1
- data/features/init_command.feature +5 -7
- data/features/install_command.feature +157 -228
- data/features/json_formatter.feature +27 -15
- data/features/licenses.feature +18 -12
- data/features/list_command.feature +6 -1
- data/features/lockfile.feature +116 -72
- data/features/outdated_command.feature +3 -47
- data/features/package_command.feature +10 -7
- data/features/shelf/show.feature +2 -2
- data/features/shelf/uninstall.feature +2 -2
- data/features/show_command.feature +10 -3
- data/features/step_definitions/chef/config_steps.rb +12 -0
- data/features/step_definitions/chef_server_steps.rb +16 -16
- data/features/step_definitions/cli_steps.rb +3 -79
- data/features/step_definitions/config_steps.rb +43 -0
- data/features/step_definitions/environment_steps.rb +7 -0
- data/features/step_definitions/filesystem_steps.rb +12 -57
- data/features/step_definitions/gem_steps.rb +1 -2
- data/features/step_definitions/json_steps.rb +3 -1
- data/features/step_definitions/lockfile_steps.rb +4 -0
- data/features/step_definitions/utility_steps.rb +0 -19
- data/features/support/aruba.rb +12 -0
- data/features/support/env.rb +52 -57
- data/features/update_command.feature +37 -23
- data/features/upload_command.feature +96 -160
- data/generator_files/Berksfile.erb +2 -1
- data/generator_files/Vagrantfile.erb +3 -0
- data/generator_files/default_test.rb.erb +1 -1
- data/generator_files/helpers.rb.erb +1 -1
- data/lib/berkshelf.rb +43 -24
- data/lib/berkshelf/api_client.rb +67 -0
- data/lib/berkshelf/api_client/remote_cookbook.rb +42 -0
- data/lib/berkshelf/berksfile.rb +232 -420
- data/lib/berkshelf/cached_cookbook.rb +22 -10
- data/lib/berkshelf/chef/config.rb +1 -0
- data/lib/berkshelf/cli.rb +66 -68
- data/lib/berkshelf/commands/shelf.rb +1 -1
- data/lib/berkshelf/community_rest.rb +10 -17
- data/lib/berkshelf/config.rb +23 -27
- data/lib/berkshelf/cookbook_generator.rb +3 -4
- data/lib/berkshelf/cookbook_store.rb +74 -17
- data/lib/berkshelf/core_ext/file.rb +2 -2
- data/lib/berkshelf/core_ext/pathname.rb +7 -5
- data/lib/berkshelf/{cookbook_source.rb → dependency.rb} +47 -67
- data/lib/berkshelf/downloader.rb +49 -106
- data/lib/berkshelf/errors.rb +64 -71
- data/lib/berkshelf/formatters.rb +11 -9
- data/lib/berkshelf/formatters/human_readable.rb +9 -9
- data/lib/berkshelf/formatters/json.rb +14 -4
- data/lib/berkshelf/init_generator.rb +3 -3
- data/lib/berkshelf/installer.rb +136 -0
- data/lib/berkshelf/location.rb +91 -131
- data/lib/berkshelf/locations/git_location.rb +9 -11
- data/lib/berkshelf/locations/github_location.rb +1 -1
- data/lib/berkshelf/locations/path_location.rb +10 -27
- data/lib/berkshelf/lockfile.rb +92 -70
- data/lib/berkshelf/logger.rb +4 -7
- data/lib/berkshelf/mixin/config.rb +21 -4
- data/lib/berkshelf/resolver.rb +60 -150
- data/lib/berkshelf/resolver/graph.rb +44 -0
- data/lib/berkshelf/source.rb +55 -0
- data/lib/berkshelf/source_uri.rb +38 -0
- data/lib/berkshelf/version.rb +1 -1
- data/spec/config/knife.rb +1 -1
- data/spec/fixtures/cassettes/Berkshelf_Resolver/_initialize/adds_the_dependencies_of_the_dependency_as_dependencies.yml +3694 -0
- data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +1 -1
- data/spec/fixtures/lockfiles/default.lock +1 -1
- data/spec/spec_helper.rb +20 -121
- data/spec/support/chef_api.rb +3 -4
- data/spec/support/chef_server.rb +20 -11
- data/spec/support/git.rb +127 -0
- data/spec/support/kitchen.rb +12 -0
- data/spec/support/path_helpers.rb +69 -0
- data/spec/unit/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
- data/spec/unit/berkshelf/api_client_spec.rb +57 -0
- data/spec/unit/berkshelf/berksfile_spec.rb +206 -324
- data/spec/unit/berkshelf/cached_cookbook_spec.rb +73 -38
- data/spec/unit/berkshelf/community_rest_spec.rb +30 -71
- data/spec/unit/berkshelf/config_spec.rb +3 -14
- data/spec/unit/berkshelf/cookbook_generator_spec.rb +1 -2
- data/spec/unit/berkshelf/cookbook_store_spec.rb +12 -7
- data/spec/unit/berkshelf/dependency_spec.rb +285 -0
- data/spec/unit/berkshelf/downloader_spec.rb +4 -183
- data/spec/unit/berkshelf/formatters/null_spec.rb +1 -1
- data/spec/unit/berkshelf/formatters_spec.rb +4 -2
- data/spec/unit/berkshelf/git_spec.rb +15 -15
- data/spec/unit/berkshelf/installer_spec.rb +39 -0
- data/spec/unit/berkshelf/location_spec.rb +87 -114
- data/spec/unit/berkshelf/locations/git_location_spec.rb +41 -53
- data/spec/unit/berkshelf/locations/path_location_spec.rb +13 -23
- data/spec/unit/berkshelf/lockfile_spec.rb +38 -40
- data/spec/unit/berkshelf/resolver/graph_spec.rb +44 -0
- data/spec/unit/berkshelf/resolver_spec.rb +34 -83
- data/spec/unit/berkshelf/source_spec.rb +23 -0
- data/spec/unit/berkshelf/source_uri_spec.rb +29 -0
- metadata +149 -188
- checksums.yaml +0 -7
- data/features/default_locations.feature +0 -127
- data/features/step_definitions/berksfile_steps.rb +0 -8
- data/features/step_definitions/configure_cli_steps.rb +0 -19
- data/features/vendor_install.feature +0 -19
- data/lib/berkshelf/core_ext/openuri.rb +0 -36
- data/lib/berkshelf/core_ext/rbzip2.rb +0 -8
- data/lib/berkshelf/locations/chef_api_location.rb +0 -228
- data/lib/berkshelf/locations/site_location.rb +0 -92
- data/lib/berkshelf/test.rb +0 -35
- data/spec/knife.rb.sample +0 -12
- data/spec/support/test_generators.rb +0 -27
- data/spec/unit/berkshelf/cli_spec.rb +0 -16
- data/spec/unit/berkshelf/cookbook_source_spec.rb +0 -358
- data/spec/unit/berkshelf/core_ext/pathname_spec.rb +0 -46
- data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +0 -139
- data/spec/unit/berkshelf/locations/site_location_spec.rb +0 -19
data/lib/berkshelf/config.rb
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'buff/config/json'
|
|
2
2
|
|
|
3
3
|
module Berkshelf
|
|
4
|
-
class Config <
|
|
5
|
-
LOCATIONS = [
|
|
6
|
-
File.join('.', '.berkshelf', 'config.json').freeze,
|
|
7
|
-
File.join('.', 'berkshelf', 'config.json').freeze,
|
|
8
|
-
File.join('.', 'berkshelf-config.json').freeze,
|
|
9
|
-
File.join('.', 'config.json').freeze
|
|
10
|
-
].freeze
|
|
11
|
-
|
|
4
|
+
class Config < Buff::Config::JSON
|
|
12
5
|
class << self
|
|
13
6
|
# @return [String]
|
|
14
|
-
def
|
|
7
|
+
def store_location
|
|
15
8
|
File.join(Berkshelf.berkshelf_path, 'config.json')
|
|
16
9
|
end
|
|
17
10
|
|
|
11
|
+
# @return [String]
|
|
12
|
+
def local_location
|
|
13
|
+
ENV['BERKSHELF_CONFIG'] || File.join('.', '.berkshelf', 'config.json')
|
|
14
|
+
end
|
|
15
|
+
|
|
18
16
|
# @return [String]
|
|
19
17
|
def path
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
File.exists?(path)
|
|
24
|
-
end
|
|
18
|
+
path = File.exists?(local_location) ? local_location : store_location
|
|
19
|
+
File.expand_path(path)
|
|
20
|
+
end
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
# @param [Berkshelf::Config] config
|
|
23
|
+
def set_config(config)
|
|
24
|
+
@instance = config
|
|
28
25
|
end
|
|
29
26
|
|
|
30
27
|
# @param [String] new_path
|
|
31
28
|
def set_path(new_path)
|
|
32
29
|
@instance = nil
|
|
33
|
-
@path = File.expand_path(new_path)
|
|
34
30
|
end
|
|
35
31
|
|
|
36
32
|
# @return [String, nil]
|
|
@@ -62,35 +58,35 @@ module Berkshelf
|
|
|
62
58
|
|
|
63
59
|
# @param [String] path
|
|
64
60
|
# @param [Hash] options
|
|
65
|
-
# @see {
|
|
61
|
+
# @see {Buff::Config::JSON}
|
|
66
62
|
def initialize(path = self.class.path, options = {})
|
|
67
63
|
super(path, options)
|
|
68
64
|
end
|
|
69
65
|
|
|
70
66
|
attribute 'chef.chef_server_url',
|
|
71
67
|
type: String,
|
|
72
|
-
default: Berkshelf.chef_config
|
|
68
|
+
default: Berkshelf.chef_config.chef_server_url
|
|
73
69
|
attribute 'chef.validation_client_name',
|
|
74
70
|
type: String,
|
|
75
|
-
default: Berkshelf.chef_config
|
|
71
|
+
default: Berkshelf.chef_config.validation_client_name
|
|
76
72
|
attribute 'chef.validation_key_path',
|
|
77
73
|
type: String,
|
|
78
|
-
default: Berkshelf.chef_config
|
|
74
|
+
default: Berkshelf.chef_config.validation_key
|
|
79
75
|
attribute 'chef.client_key',
|
|
80
76
|
type: String,
|
|
81
|
-
default: Berkshelf.chef_config
|
|
77
|
+
default: Berkshelf.chef_config.client_key
|
|
82
78
|
attribute 'chef.node_name',
|
|
83
79
|
type: String,
|
|
84
|
-
default: Berkshelf.chef_config
|
|
80
|
+
default: Berkshelf.chef_config.node_name
|
|
85
81
|
attribute 'cookbook.copyright',
|
|
86
82
|
type: String,
|
|
87
|
-
default: Berkshelf.chef_config
|
|
83
|
+
default: Berkshelf.chef_config.cookbook_copyright
|
|
88
84
|
attribute 'cookbook.email',
|
|
89
85
|
type: String,
|
|
90
|
-
default: Berkshelf.chef_config
|
|
86
|
+
default: Berkshelf.chef_config.cookbook_email
|
|
91
87
|
attribute 'cookbook.license',
|
|
92
88
|
type: String,
|
|
93
|
-
default: Berkshelf.chef_config
|
|
89
|
+
default: Berkshelf.chef_config.cookbook_license
|
|
94
90
|
attribute 'allowed_licenses',
|
|
95
91
|
type: Array,
|
|
96
92
|
default: Array.new
|
|
@@ -45,21 +45,20 @@ module Berkshelf
|
|
|
45
45
|
|
|
46
46
|
class_option :license,
|
|
47
47
|
type: :string,
|
|
48
|
-
default: Berkshelf
|
|
48
|
+
default: Berkshelf.config.cookbook.license
|
|
49
49
|
|
|
50
50
|
class_option :maintainer,
|
|
51
51
|
type: :string,
|
|
52
|
-
default: Berkshelf
|
|
52
|
+
default: Berkshelf.config.cookbook.copyright
|
|
53
53
|
|
|
54
54
|
class_option :maintainer_email,
|
|
55
55
|
type: :string,
|
|
56
|
-
default: Berkshelf
|
|
56
|
+
default: Berkshelf.config.cookbook.email
|
|
57
57
|
|
|
58
58
|
def generate
|
|
59
59
|
empty_directory target.join('files/default')
|
|
60
60
|
empty_directory target.join('templates/default')
|
|
61
61
|
empty_directory target.join('attributes')
|
|
62
|
-
empty_directory target.join('definitions')
|
|
63
62
|
empty_directory target.join('libraries')
|
|
64
63
|
empty_directory target.join('providers')
|
|
65
64
|
empty_directory target.join('recipes')
|
|
@@ -2,6 +2,35 @@ require 'fileutils'
|
|
|
2
2
|
|
|
3
3
|
module Berkshelf
|
|
4
4
|
class CookbookStore
|
|
5
|
+
class << self
|
|
6
|
+
# The default path to the cookbook store relative to the Berkshelf path.
|
|
7
|
+
#
|
|
8
|
+
# @return [String]
|
|
9
|
+
def default_path
|
|
10
|
+
File.join(Berkshelf.berkshelf_path, 'cookbooks')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @return [Berkshelf::CookbookStore]
|
|
14
|
+
def instance
|
|
15
|
+
@instance ||= new(default_path)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Import a cookbook found on the local filesystem into the current instance of
|
|
19
|
+
# the cookbook store.
|
|
20
|
+
#
|
|
21
|
+
# @param [String] name
|
|
22
|
+
# name of the cookbook
|
|
23
|
+
# @param [String] version
|
|
24
|
+
# verison of the cookbook
|
|
25
|
+
# @param [String] path
|
|
26
|
+
# location on disk of the cookbook
|
|
27
|
+
#
|
|
28
|
+
# @return [Berkshelf::CachedCookbook]
|
|
29
|
+
def import(name, version, path)
|
|
30
|
+
instance.import(name, version, path)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
5
34
|
# @return [String]
|
|
6
35
|
# filepath to where cookbooks are stored
|
|
7
36
|
attr_reader :storage_path
|
|
@@ -17,6 +46,30 @@ module Berkshelf
|
|
|
17
46
|
initialize_filesystem
|
|
18
47
|
end
|
|
19
48
|
|
|
49
|
+
# Destroy the contents of the initialized storage path.
|
|
50
|
+
def clean!
|
|
51
|
+
FileUtils.rm_rf(Dir.glob(File.join(storage_path, '*')))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Import a cookbook found on the local filesystem into this instance of the cookbook store.
|
|
55
|
+
#
|
|
56
|
+
# @param [String] name
|
|
57
|
+
# name of the cookbook
|
|
58
|
+
# @param [String] version
|
|
59
|
+
# verison of the cookbook
|
|
60
|
+
# @param [String] path
|
|
61
|
+
# location on disk of the cookbook
|
|
62
|
+
#
|
|
63
|
+
# @return [Berkshelf::CachedCookbook]
|
|
64
|
+
def import(name, version, path)
|
|
65
|
+
destination = cookbook_path(name, version)
|
|
66
|
+
FileUtils.mv(path, destination)
|
|
67
|
+
cookbook(name, version)
|
|
68
|
+
rescue => ex
|
|
69
|
+
FileUtils.rm_f(destination)
|
|
70
|
+
raise
|
|
71
|
+
end
|
|
72
|
+
|
|
20
73
|
# Returns an instance of CachedCookbook representing the
|
|
21
74
|
# Cookbook of your given name and version.
|
|
22
75
|
#
|
|
@@ -41,15 +94,20 @@ module Berkshelf
|
|
|
41
94
|
#
|
|
42
95
|
# @return [Array<Berkshelf::CachedCookbook>]
|
|
43
96
|
def cookbooks(filter = nil)
|
|
44
|
-
cookbooks =
|
|
45
|
-
CachedCookbook.from_store_path(path)
|
|
46
|
-
end.compact
|
|
97
|
+
cookbooks = []
|
|
47
98
|
|
|
48
|
-
|
|
99
|
+
storage_path.each_child.map do |path|
|
|
100
|
+
Celluloid::Future.new do
|
|
101
|
+
cached_cookbook = CachedCookbook.from_store_path(path)
|
|
49
102
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
103
|
+
next unless cached_cookbook
|
|
104
|
+
next if filter && cached_cookbook.cookbook_name != filter
|
|
105
|
+
|
|
106
|
+
cookbooks << cached_cookbook
|
|
107
|
+
end
|
|
108
|
+
end.each(&:value)
|
|
109
|
+
|
|
110
|
+
cookbooks
|
|
53
111
|
end
|
|
54
112
|
|
|
55
113
|
# Returns an expanded path to the location on disk where the Cookbook
|
|
@@ -63,6 +121,15 @@ module Berkshelf
|
|
|
63
121
|
storage_path.join("#{name}-#{version}")
|
|
64
122
|
end
|
|
65
123
|
|
|
124
|
+
def initialize_filesystem
|
|
125
|
+
FileUtils.mkdir_p(storage_path, mode: 0755)
|
|
126
|
+
|
|
127
|
+
unless File.writable?(storage_path)
|
|
128
|
+
raise InsufficientPrivledges, "You do not have permission to write to '#{storage_path}'!" +
|
|
129
|
+
" Please either chown the directory or use a different Cookbook Store."
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
66
133
|
# Return a CachedCookbook matching the best solution for the given name and
|
|
67
134
|
# constraint. Nil is returned if no matching CachedCookbook is found.
|
|
68
135
|
#
|
|
@@ -80,15 +147,5 @@ module Berkshelf
|
|
|
80
147
|
rescue Solve::Errors::NoSolutionError
|
|
81
148
|
nil
|
|
82
149
|
end
|
|
83
|
-
|
|
84
|
-
private
|
|
85
|
-
|
|
86
|
-
def initialize_filesystem
|
|
87
|
-
FileUtils.mkdir_p(storage_path, mode: 0755)
|
|
88
|
-
|
|
89
|
-
unless File.writable?(storage_path)
|
|
90
|
-
raise InsufficientPrivledges, "You do not have permission to write to '#{storage_path}'! Please either chown the directory or use a different Cookbook Store."
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
150
|
end
|
|
94
151
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
class File
|
|
2
2
|
class << self
|
|
3
|
-
# Returns true or false if the given path
|
|
3
|
+
# Returns true or false if the given path is a Chef Cookbook
|
|
4
4
|
#
|
|
5
5
|
# @param [#to_s] path
|
|
6
6
|
# path of directory to reflect on
|
|
7
7
|
#
|
|
8
8
|
# @return [Boolean]
|
|
9
9
|
def cookbook?(path)
|
|
10
|
-
File.exists?(File.join(path,
|
|
10
|
+
File.exists?(File.join(path, 'metadata.rb'))
|
|
11
11
|
end
|
|
12
12
|
alias_method :chef_cookbook?, :cookbook?
|
|
13
13
|
end
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
class Pathname
|
|
2
|
-
# Returns true or false if the path
|
|
2
|
+
# Returns true or false if the path of the instantiated
|
|
3
|
+
# Pathname or a parent directory contains a Tryhard Pack
|
|
4
|
+
# data directory.
|
|
3
5
|
#
|
|
4
6
|
# @return [Boolean]
|
|
5
7
|
def cookbook?
|
|
6
|
-
|
|
8
|
+
self.join('metadata.rb').exist?
|
|
7
9
|
end
|
|
8
10
|
alias_method :chef_cookbook?, :cookbook?
|
|
9
11
|
|
|
10
|
-
# Ascend the directory structure from the given path to find
|
|
11
|
-
# Cookbook. If no Cookbook is found, nil is returned
|
|
12
|
+
# Ascend the directory structure from the given path to find a
|
|
13
|
+
# the root of a Chef Cookbook. If no Cookbook is found, nil is returned
|
|
12
14
|
#
|
|
13
15
|
# @return [Pathname, nil]
|
|
14
16
|
def cookbook_root
|
|
15
|
-
ascend do |potential_root|
|
|
17
|
+
self.ascend do |potential_root|
|
|
16
18
|
if potential_root.cookbook?
|
|
17
19
|
return potential_root
|
|
18
20
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Berkshelf
|
|
2
|
-
class
|
|
2
|
+
class Dependency
|
|
3
3
|
class << self
|
|
4
4
|
@@valid_options = [:constraint, :locations, :group, :locked_version]
|
|
5
5
|
@@location_keys = Hash.new
|
|
@@ -13,7 +13,7 @@ module Berkshelf
|
|
|
13
13
|
|
|
14
14
|
# Returns an array of the registered source location keys. Every source
|
|
15
15
|
# location is identified by a key (symbol) to differentiate which class
|
|
16
|
-
# to instantiate for the location of a
|
|
16
|
+
# to instantiate for the location of a Dependency at initialization.
|
|
17
17
|
#
|
|
18
18
|
# @return [Array<Symbol>]
|
|
19
19
|
def location_keys
|
|
@@ -31,7 +31,7 @@ module Berkshelf
|
|
|
31
31
|
@@valid_options
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
# Register a location key with the
|
|
34
|
+
# Register a location key with the Dependency class
|
|
35
35
|
# @see #location_keys
|
|
36
36
|
#
|
|
37
37
|
# @param [Symbol] location
|
|
@@ -53,19 +53,20 @@ module Berkshelf
|
|
|
53
53
|
|
|
54
54
|
unless invalid_options.empty?
|
|
55
55
|
invalid_options.collect! { |opt| "'#{opt}'" }
|
|
56
|
-
raise InternalError, "Invalid options for
|
|
56
|
+
raise InternalError, "Invalid options for dependency: #{invalid_options.join(', ')}."
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
if (options.keys &
|
|
60
|
-
invalid = (options.keys &
|
|
61
|
-
raise InternalError, "Cannot specify #{invalid.
|
|
59
|
+
if (options.keys & location_keys.keys).size > 1
|
|
60
|
+
invalid = (options.keys & location_keys.keys).map { |opt| "'#{opt}'" }
|
|
61
|
+
raise InternalError, "Cannot specify #{invalid.join(' and ')} for a dependency!"
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
true
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
DEFAULT_CONSTRAINT = '>= 0.0.0'
|
|
68
|
+
DEFAULT_CONSTRAINT = '>= 0.0.0'.freeze
|
|
69
|
+
SCM_LOCATIONS = [ :git, :github ].freeze
|
|
69
70
|
|
|
70
71
|
# @return [Berkshelf::Berksfile]
|
|
71
72
|
attr_reader :berksfile
|
|
@@ -81,16 +82,14 @@ module Berkshelf
|
|
|
81
82
|
attr_accessor :cached_cookbook
|
|
82
83
|
|
|
83
84
|
# @param [Berkshelf::Berksfile] berksfile
|
|
84
|
-
# the berksfile this
|
|
85
|
+
# the berksfile this dependency belongs to
|
|
85
86
|
# @param [String] name
|
|
86
|
-
# the name of
|
|
87
|
+
# the name of dependency
|
|
87
88
|
#
|
|
88
89
|
# @option options [String, Solve::Constraint] :constraint
|
|
89
|
-
# version constraint
|
|
90
|
+
# version constraint for this dependency
|
|
90
91
|
# @option options [String] :git
|
|
91
92
|
# the Git URL to clone
|
|
92
|
-
# @option options [String] :site
|
|
93
|
-
# a URL pointing to a community API endpoint
|
|
94
93
|
# @option options [String] :path
|
|
95
94
|
# a filepath to the cookbook on your local disk
|
|
96
95
|
# @option options [String] :metadata
|
|
@@ -105,17 +104,15 @@ module Berkshelf
|
|
|
105
104
|
# same as tag
|
|
106
105
|
# @option options [String] :locked_version
|
|
107
106
|
def initialize(berksfile, name, options = {})
|
|
108
|
-
@options = options
|
|
109
|
-
|
|
110
107
|
self.class.validate_options(options)
|
|
111
108
|
|
|
109
|
+
@options = options
|
|
112
110
|
@berksfile = berksfile
|
|
113
111
|
@name = name
|
|
112
|
+
@location = Location.init(self, options)
|
|
114
113
|
@locked_version = Solve::Version.new(options[:locked_version]) if options[:locked_version]
|
|
115
114
|
@version_constraint = Solve::Constraint.new(options[:constraint] || DEFAULT_CONSTRAINT)
|
|
116
115
|
|
|
117
|
-
@cached_cookbook, @location = cached_and_location(options)
|
|
118
|
-
|
|
119
116
|
add_group(options[:group]) if options[:group]
|
|
120
117
|
add_group(:default) if groups.empty?
|
|
121
118
|
end
|
|
@@ -129,22 +126,29 @@ module Berkshelf
|
|
|
129
126
|
end
|
|
130
127
|
end
|
|
131
128
|
|
|
132
|
-
#
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
# @return [Berkshelf::CachedCookbook]
|
|
130
|
+
def cached_cookbook
|
|
131
|
+
@cached_cookbook ||= if location
|
|
132
|
+
location.download
|
|
133
|
+
else
|
|
134
|
+
Berkshelf::CookbookStore.instance.satisfy(name, version_constraint)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# @return [Berkshelf::CachedCookbook]
|
|
139
|
+
def download
|
|
140
|
+
@cached_cookbook = location.download
|
|
137
141
|
end
|
|
138
142
|
|
|
139
|
-
# Returns true if the
|
|
140
|
-
#
|
|
143
|
+
# Returns true if the dependency has already been downloaded. A dependency is downloaded when a
|
|
144
|
+
# cached cookbook is present.
|
|
141
145
|
#
|
|
142
146
|
# @return [Boolean]
|
|
143
147
|
def downloaded?
|
|
144
|
-
!
|
|
148
|
+
!cached_cookbook.nil?
|
|
145
149
|
end
|
|
146
150
|
|
|
147
|
-
# Returns true if this
|
|
151
|
+
# Returns true if this dependency has the given group.
|
|
148
152
|
#
|
|
149
153
|
# @return [Boolean]
|
|
150
154
|
def has_group?(group)
|
|
@@ -160,10 +164,10 @@ module Berkshelf
|
|
|
160
164
|
# @return [Solve::Version, nil]
|
|
161
165
|
# the locked version of this cookbook
|
|
162
166
|
def locked_version
|
|
163
|
-
@locked_version ||= cached_cookbook.
|
|
167
|
+
@locked_version ||= cached_cookbook ? cached_cookbook.version : nil
|
|
164
168
|
end
|
|
165
169
|
|
|
166
|
-
# The location for this
|
|
170
|
+
# The location for this dependency, such as a remote Chef Server, the
|
|
167
171
|
# community API, :git, or a :path location. By default, this will be the
|
|
168
172
|
# community API.
|
|
169
173
|
#
|
|
@@ -172,21 +176,30 @@ module Berkshelf
|
|
|
172
176
|
@location
|
|
173
177
|
end
|
|
174
178
|
|
|
175
|
-
# The list of groups this
|
|
179
|
+
# The list of groups this dependency belongs to.
|
|
176
180
|
#
|
|
177
181
|
# @return [Array<Symbol>]
|
|
178
182
|
def groups
|
|
179
183
|
@groups ||= []
|
|
180
184
|
end
|
|
181
185
|
|
|
186
|
+
# @return [Boolean]
|
|
187
|
+
def scm_location?
|
|
188
|
+
if location.nil?
|
|
189
|
+
return false
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
SCM_LOCATIONS.include?(location.class.location_key)
|
|
193
|
+
end
|
|
194
|
+
|
|
182
195
|
def to_s
|
|
183
|
-
"
|
|
196
|
+
"#{name} (#{version_constraint})"
|
|
184
197
|
end
|
|
185
198
|
|
|
186
199
|
def inspect
|
|
187
|
-
'#<Berkshelf::
|
|
200
|
+
'#<Berkshelf::Dependency: ' << [
|
|
188
201
|
"#{name} (#{version_constraint})",
|
|
189
|
-
"locked_version: #{locked_version
|
|
202
|
+
"locked_version: #{locked_version.inspect}",
|
|
190
203
|
"groups: #{groups}",
|
|
191
204
|
"location: #{location || 'default'}>"
|
|
192
205
|
].join(', ')
|
|
@@ -198,8 +211,8 @@ module Berkshelf
|
|
|
198
211
|
h[:locked_version] = locked_version.to_s
|
|
199
212
|
end
|
|
200
213
|
|
|
201
|
-
|
|
202
|
-
h[:
|
|
214
|
+
unless version_constraint.to_s == DEFAULT_CONSTRAINT
|
|
215
|
+
h[:constraint] = version_constraint.to_s
|
|
203
216
|
end
|
|
204
217
|
|
|
205
218
|
if location.kind_of?(PathLocation)
|
|
@@ -217,38 +230,5 @@ module Berkshelf
|
|
|
217
230
|
def to_json(options = {})
|
|
218
231
|
JSON.pretty_generate(to_hash, options)
|
|
219
232
|
end
|
|
220
|
-
|
|
221
|
-
private
|
|
222
|
-
# Attempt to load a CachedCookbook from a local file system path (if the :path
|
|
223
|
-
# option was given). If one is found, the location and cached_cookbook is
|
|
224
|
-
# updated. Otherwise, this method will raise a CookbookNotFound exception.
|
|
225
|
-
#
|
|
226
|
-
# @raise [Berkshelf::CookbookNotFound]
|
|
227
|
-
# if no CachedCookbook exists at the given path
|
|
228
|
-
#
|
|
229
|
-
# @return [Berkshelf::CachedCookbook]
|
|
230
|
-
def from_path(options = {})
|
|
231
|
-
return nil unless options[:path]
|
|
232
|
-
|
|
233
|
-
location = PathLocation.new(name, version_constraint, options)
|
|
234
|
-
|
|
235
|
-
[ location.cookbook, location ]
|
|
236
|
-
rescue IOError => ex
|
|
237
|
-
raise Berkshelf::CookbookNotFound, ex
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
# Use the default location, and a nil CachedCookbook. If there is no location
|
|
241
|
-
# specified,
|
|
242
|
-
#
|
|
243
|
-
# @return [Array<nil, Location>]
|
|
244
|
-
def from_default(options = {})
|
|
245
|
-
if (options.keys & self.class.location_keys.keys).empty?
|
|
246
|
-
location = nil
|
|
247
|
-
else
|
|
248
|
-
location = Location.init(name, version_constraint, options)
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
[ nil, location ]
|
|
252
|
-
end
|
|
253
233
|
end
|
|
254
234
|
end
|