chef-config 12.8.1 → 12.9.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -201
- data/README.md +4 -4
- data/Rakefile +13 -13
- data/chef-config.gemspec +33 -32
- data/lib/chef-config.rb +20 -20
- data/lib/chef-config/config.rb +967 -935
- data/lib/chef-config/exceptions.rb +26 -26
- data/lib/chef-config/logger.rb +59 -59
- data/lib/chef-config/mixin/dot_d.rb +38 -38
- data/lib/chef-config/mixin/fuzzy_hostname_matcher.rb +39 -0
- data/lib/chef-config/package_task.rb +244 -222
- data/lib/chef-config/path_helper.rb +283 -272
- data/lib/chef-config/version.rb +34 -34
- data/lib/chef-config/windows.rb +28 -28
- data/lib/chef-config/workstation_config_loader.rb +182 -182
- data/spec/spec_helper.rb +75 -75
- data/spec/unit/config_spec.rb +995 -843
- data/spec/unit/path_helper_spec.rb +307 -307
- data/spec/unit/workstation_config_loader_spec.rb +366 -366
- metadata +18 -3
@@ -1,26 +1,26 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright 2015-2016, Chef Software, Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require "chef-config/windows"
|
19
|
-
require "chef-config/logger"
|
20
|
-
|
21
|
-
module ChefConfig
|
22
|
-
|
23
|
-
class ConfigurationError < ArgumentError; end
|
24
|
-
class InvalidPath < StandardError; end
|
25
|
-
|
26
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2015-2016, Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "chef-config/windows"
|
19
|
+
require "chef-config/logger"
|
20
|
+
|
21
|
+
module ChefConfig
|
22
|
+
|
23
|
+
class ConfigurationError < ArgumentError; end
|
24
|
+
class InvalidPath < StandardError; end
|
25
|
+
|
26
|
+
end
|
data/lib/chef-config/logger.rb
CHANGED
@@ -1,59 +1,59 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright 2015-2016, Chef Software, Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
module ChefConfig
|
19
|
-
|
20
|
-
# Implements enough of Logger's API that we can use it in place of a real
|
21
|
-
# logger for `ChefConfig.logger`
|
22
|
-
class NullLogger
|
23
|
-
|
24
|
-
def <<(_msg)
|
25
|
-
end
|
26
|
-
|
27
|
-
def add(_severity, _message = nil, _progname = nil)
|
28
|
-
end
|
29
|
-
|
30
|
-
def debug(_progname = nil, &block)
|
31
|
-
end
|
32
|
-
|
33
|
-
def info(_progname = nil, &block)
|
34
|
-
end
|
35
|
-
|
36
|
-
def warn(_progname = nil, &block)
|
37
|
-
end
|
38
|
-
|
39
|
-
def deprecation(_progname = nil, &block)
|
40
|
-
end
|
41
|
-
|
42
|
-
def error(_progname = nil, &block)
|
43
|
-
end
|
44
|
-
|
45
|
-
def fatal(_progname = nil, &block)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
@logger = NullLogger.new
|
51
|
-
|
52
|
-
def self.logger=(new_logger)
|
53
|
-
@logger = new_logger
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.logger
|
57
|
-
@logger
|
58
|
-
end
|
59
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2015-2016, Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module ChefConfig
|
19
|
+
|
20
|
+
# Implements enough of Logger's API that we can use it in place of a real
|
21
|
+
# logger for `ChefConfig.logger`
|
22
|
+
class NullLogger
|
23
|
+
|
24
|
+
def <<(_msg)
|
25
|
+
end
|
26
|
+
|
27
|
+
def add(_severity, _message = nil, _progname = nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
def debug(_progname = nil, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def info(_progname = nil, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def warn(_progname = nil, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def deprecation(_progname = nil, &block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def error(_progname = nil, &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def fatal(_progname = nil, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
@logger = NullLogger.new
|
51
|
+
|
52
|
+
def self.logger=(new_logger)
|
53
|
+
@logger = new_logger
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.logger
|
57
|
+
@logger
|
58
|
+
end
|
59
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright 2016, Chef Software Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require "chef-config/path_helper"
|
18
|
-
|
19
|
-
module ChefConfig
|
20
|
-
module Mixin
|
21
|
-
module DotD
|
22
|
-
def load_dot_d(path)
|
23
|
-
dot_d_files =
|
24
|
-
begin
|
25
|
-
entries = Array.new
|
26
|
-
entries << Dir.glob(File.join(
|
27
|
-
ChefConfig::PathHelper.escape_glob_dir(path), "*.rb"))
|
28
|
-
entries.flatten.select do |entry|
|
29
|
-
File.file?(entry)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
dot_d_files.sort.map do |conf|
|
33
|
-
apply_config(IO.read(conf), conf)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "chef-config/path_helper"
|
18
|
+
|
19
|
+
module ChefConfig
|
20
|
+
module Mixin
|
21
|
+
module DotD
|
22
|
+
def load_dot_d(path)
|
23
|
+
dot_d_files =
|
24
|
+
begin
|
25
|
+
entries = Array.new
|
26
|
+
entries << Dir.glob(File.join(
|
27
|
+
ChefConfig::PathHelper.escape_glob_dir(path), "*.rb"))
|
28
|
+
entries.flatten.select do |entry|
|
29
|
+
File.file?(entry)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
dot_d_files.sort.map do |conf|
|
33
|
+
apply_config(IO.read(conf), conf)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "fuzzyurl"
|
18
|
+
|
19
|
+
module ChefConfig
|
20
|
+
module Mixin
|
21
|
+
module FuzzyHostnameMatcher
|
22
|
+
|
23
|
+
def fuzzy_hostname_match_any?(hostname, matches)
|
24
|
+
return matches.to_s.split(/\s*,\s*/).compact.any? {
|
25
|
+
|m| fuzzy_hostname_match?(hostname, m)
|
26
|
+
} if (hostname != nil) && (matches != nil)
|
27
|
+
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def fuzzy_hostname_match?(hostname, match)
|
32
|
+
# Do greedy matching by adding wildcard if it is not specified
|
33
|
+
match = "*" + match if !match.start_with?("*")
|
34
|
+
Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,222 +1,244 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Kartik Null Cating-Subramanian (<ksubramanian@chef.io>)
|
3
|
-
# Copyright:: Copyright 2015-2016, Chef, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require "rake"
|
20
|
-
require "rubygems"
|
21
|
-
require "rubygems/package_task"
|
22
|
-
|
23
|
-
module ChefConfig
|
24
|
-
class PackageTask < Rake::TaskLib
|
25
|
-
|
26
|
-
# Full path to root of top-level repository. All other files (like VERSION or
|
27
|
-
# lib/<module_path>/version.rb are rooted at this path).
|
28
|
-
attr_accessor :root_path
|
29
|
-
|
30
|
-
# Name of the top-level module/library build built. This is used to define
|
31
|
-
# the top level module which contains VERSION and MODULE_ROOT.
|
32
|
-
attr_accessor :module_name
|
33
|
-
|
34
|
-
# Should the generated version.rb be in a class or module? Default is false (module).
|
35
|
-
attr_accessor :generate_version_class
|
36
|
-
|
37
|
-
# Paths to the roots of any components that also support ChefPackageTask.
|
38
|
-
# If relative paths are provided, they are rooted against root_path.
|
39
|
-
attr_accessor :component_paths
|
40
|
-
|
41
|
-
# This is the module name as it appears on the path "lib/module/".
|
42
|
-
# e.g. for module_name "ChefDK", you'd want module_path to be "chef-dk".
|
43
|
-
# The default is module_name but lower-cased.
|
44
|
-
attr_writer :module_path
|
45
|
-
|
46
|
-
def module_path
|
47
|
-
@module_path || module_name.downcase
|
48
|
-
end
|
49
|
-
|
50
|
-
# Directory used to store package files and output that is generated.
|
51
|
-
# This has the same meaning (or lack thereof) as package_dir in
|
52
|
-
# rake/packagetask.
|
53
|
-
attr_accessor :package_dir
|
54
|
-
|
55
|
-
# Name of git remote used to push tags during a release. Default is origin.
|
56
|
-
attr_accessor :git_remote
|
57
|
-
|
58
|
-
def initialize(root_path = nil, module_name = nil)
|
59
|
-
init(root_path, module_name)
|
60
|
-
yield self if block_given?
|
61
|
-
define unless root_path.nil? || module_name.nil?
|
62
|
-
end
|
63
|
-
|
64
|
-
def init(root_path, module_name)
|
65
|
-
@root_path = root_path
|
66
|
-
@module_name = module_name
|
67
|
-
@component_paths = []
|
68
|
-
@module_path = nil
|
69
|
-
@package_dir = "pkg"
|
70
|
-
@git_remote = "origin"
|
71
|
-
@generate_version_class = false
|
72
|
-
end
|
73
|
-
|
74
|
-
def component_full_paths
|
75
|
-
component_paths.map { |path| File.expand_path(path, root_path) }
|
76
|
-
end
|
77
|
-
|
78
|
-
def version_rb_path
|
79
|
-
File.expand_path("lib/#{module_path}/version.rb", root_path)
|
80
|
-
end
|
81
|
-
|
82
|
-
def chef_root_path
|
83
|
-
module_name == "Chef" ? root_path : File.dirname(root_path)
|
84
|
-
end
|
85
|
-
|
86
|
-
def
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
def
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
def
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
def
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
|
169
|
-
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
|
174
|
-
|
175
|
-
#
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
|
184
|
-
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
task :
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
1
|
+
#
|
2
|
+
# Author:: Kartik Null Cating-Subramanian (<ksubramanian@chef.io>)
|
3
|
+
# Copyright:: Copyright 2015-2016, Chef, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require "rake"
|
20
|
+
require "rubygems"
|
21
|
+
require "rubygems/package_task"
|
22
|
+
|
23
|
+
module ChefConfig
|
24
|
+
class PackageTask < Rake::TaskLib
|
25
|
+
|
26
|
+
# Full path to root of top-level repository. All other files (like VERSION or
|
27
|
+
# lib/<module_path>/version.rb are rooted at this path).
|
28
|
+
attr_accessor :root_path
|
29
|
+
|
30
|
+
# Name of the top-level module/library build built. This is used to define
|
31
|
+
# the top level module which contains VERSION and MODULE_ROOT.
|
32
|
+
attr_accessor :module_name
|
33
|
+
|
34
|
+
# Should the generated version.rb be in a class or module? Default is false (module).
|
35
|
+
attr_accessor :generate_version_class
|
36
|
+
|
37
|
+
# Paths to the roots of any components that also support ChefPackageTask.
|
38
|
+
# If relative paths are provided, they are rooted against root_path.
|
39
|
+
attr_accessor :component_paths
|
40
|
+
|
41
|
+
# This is the module name as it appears on the path "lib/module/".
|
42
|
+
# e.g. for module_name "ChefDK", you'd want module_path to be "chef-dk".
|
43
|
+
# The default is module_name but lower-cased.
|
44
|
+
attr_writer :module_path
|
45
|
+
|
46
|
+
def module_path
|
47
|
+
@module_path || module_name.downcase
|
48
|
+
end
|
49
|
+
|
50
|
+
# Directory used to store package files and output that is generated.
|
51
|
+
# This has the same meaning (or lack thereof) as package_dir in
|
52
|
+
# rake/packagetask.
|
53
|
+
attr_accessor :package_dir
|
54
|
+
|
55
|
+
# Name of git remote used to push tags during a release. Default is origin.
|
56
|
+
attr_accessor :git_remote
|
57
|
+
|
58
|
+
def initialize(root_path = nil, module_name = nil)
|
59
|
+
init(root_path, module_name)
|
60
|
+
yield self if block_given?
|
61
|
+
define unless root_path.nil? || module_name.nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
def init(root_path, module_name)
|
65
|
+
@root_path = root_path
|
66
|
+
@module_name = module_name
|
67
|
+
@component_paths = []
|
68
|
+
@module_path = nil
|
69
|
+
@package_dir = "pkg"
|
70
|
+
@git_remote = "origin"
|
71
|
+
@generate_version_class = false
|
72
|
+
end
|
73
|
+
|
74
|
+
def component_full_paths
|
75
|
+
component_paths.map { |path| File.expand_path(path, root_path) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def version_rb_path
|
79
|
+
File.expand_path("lib/#{module_path}/version.rb", root_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
def chef_root_path
|
83
|
+
module_name == "Chef" ? root_path : File.dirname(root_path)
|
84
|
+
end
|
85
|
+
|
86
|
+
def version_file_path
|
87
|
+
File.join(chef_root_path, "VERSION")
|
88
|
+
end
|
89
|
+
|
90
|
+
def version
|
91
|
+
IO.read(version_file_path).strip
|
92
|
+
end
|
93
|
+
|
94
|
+
def full_package_dir
|
95
|
+
File.expand_path(package_dir, root_path)
|
96
|
+
end
|
97
|
+
|
98
|
+
def class_or_module
|
99
|
+
generate_version_class ? "class" : "module"
|
100
|
+
end
|
101
|
+
|
102
|
+
def with_clean_env(&block)
|
103
|
+
if defined?(Bundler)
|
104
|
+
Bundler.with_clean_env(&block)
|
105
|
+
else
|
106
|
+
yield
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def define
|
111
|
+
raise "Need to provide package root and module name" if root_path.nil? || module_name.nil?
|
112
|
+
|
113
|
+
desc "Build Gems of component dependencies"
|
114
|
+
task :package_components do
|
115
|
+
component_full_paths.each do |component_path|
|
116
|
+
Dir.chdir(component_path) do
|
117
|
+
sh "rake package"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
task :package => :package_components
|
123
|
+
|
124
|
+
desc "Build and install component dependencies"
|
125
|
+
task :install_components => :package_components do
|
126
|
+
component_full_paths.each do |component_path|
|
127
|
+
Dir.chdir(component_path) do
|
128
|
+
sh "rake install"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
task :install => :install_components
|
134
|
+
|
135
|
+
desc "Clean up builds of component dependencies"
|
136
|
+
task :clobber_component_packages do
|
137
|
+
component_full_paths.each do |component_path|
|
138
|
+
Dir.chdir(component_path) do
|
139
|
+
sh "rake clobber_package"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
task :clobber_package => :clobber_component_packages
|
145
|
+
|
146
|
+
desc "Update the version number for component dependencies"
|
147
|
+
task :update_components_versions do
|
148
|
+
component_full_paths.each do |component_path|
|
149
|
+
Dir.chdir(component_path) do
|
150
|
+
sh "rake version"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
namespace :version do
|
156
|
+
desc 'Regenerate lib/#{@module_path}/version.rb from VERSION file'
|
157
|
+
task :update => :update_components_versions do
|
158
|
+
contents = <<-VERSION_RB
|
159
|
+
# Copyright:: Copyright 2010-2016, Chef Software, Inc.
|
160
|
+
# License:: Apache License, Version 2.0
|
161
|
+
#
|
162
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
163
|
+
# you may not use this file except in compliance with the License.
|
164
|
+
# You may obtain a copy of the License at
|
165
|
+
#
|
166
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
167
|
+
#
|
168
|
+
# Unless required by applicable law or agreed to in writing, software
|
169
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
170
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
171
|
+
# See the License for the specific language governing permissions and
|
172
|
+
# limitations under the License.
|
173
|
+
|
174
|
+
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
175
|
+
# NOTE: This file is generated by running `rake version` in the top level of
|
176
|
+
# this repo. Do not edit this manually. Edit the VERSION file and run the rake
|
177
|
+
# task instead.
|
178
|
+
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
179
|
+
|
180
|
+
#{class_or_module} #{module_name}
|
181
|
+
#{module_name.upcase}_ROOT = File.expand_path("../..", __FILE__)
|
182
|
+
VERSION = "#{version}"
|
183
|
+
end
|
184
|
+
|
185
|
+
#
|
186
|
+
# NOTE: the Chef::Version class is defined in version_class.rb
|
187
|
+
#
|
188
|
+
# NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
|
189
|
+
# Chef::Version class is for _cookbooks_ only, and cannot handle
|
190
|
+
# pre-release versions like "10.14.0.rc.2". Please use Rubygem's
|
191
|
+
# Gem::Version class instead.
|
192
|
+
#
|
193
|
+
VERSION_RB
|
194
|
+
IO.write(version_rb_path, contents)
|
195
|
+
end
|
196
|
+
|
197
|
+
task :bump => %w{version:bump_patch version:update}
|
198
|
+
|
199
|
+
task :show do
|
200
|
+
puts version
|
201
|
+
end
|
202
|
+
|
203
|
+
# Add 1 to the current patch version in the VERSION file, and write it back out.
|
204
|
+
task :bump_patch do
|
205
|
+
current_version = version
|
206
|
+
new_version = current_version.sub(/^(\d+\.\d+\.)(\d+)/) { "#{$1}#{$2.to_i + 1}" }
|
207
|
+
puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
|
208
|
+
IO.write(version_file_path, new_version)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
task :version => "version:update"
|
213
|
+
|
214
|
+
Dir[File.expand_path("*gemspec", root_path)].reverse_each do |gemspec_path|
|
215
|
+
gemspec = eval(IO.read(gemspec_path))
|
216
|
+
Gem::PackageTask.new(gemspec) do |task|
|
217
|
+
task.package_dir = full_package_dir
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
desc "Build and install a #{module_path} gem"
|
222
|
+
task :install => [:package] do
|
223
|
+
with_clean_env do
|
224
|
+
full_module_path = File.join(full_package_dir, module_path)
|
225
|
+
sh %{gem install #{full_module_path}-#{version}.gem --no-rdoc --no-ri}
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
task :uninstall do
|
230
|
+
sh %{gem uninstall #{module_path} -x -v #{version} }
|
231
|
+
end
|
232
|
+
|
233
|
+
desc "Build it, tag it and ship it"
|
234
|
+
task :ship => [:clobber_package, :gem] do
|
235
|
+
sh("git tag #{version}")
|
236
|
+
sh("git push #{git_remote} --tags")
|
237
|
+
Dir[File.expand_path("*.gem", full_package_dir)].reverse_each do |built_gem|
|
238
|
+
sh("gem push #{built_gem}")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
end
|