chef-config 12.22.1 → 12.22.3

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.
@@ -1,27 +1,27 @@
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
- class UnparsableConfigOption < StandardError; end
26
-
27
- 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
+ class UnparsableConfigOption < StandardError; end
26
+
27
+ end
@@ -1,51 +1,51 @@
1
- #
2
- # Author:: Matt Wrock (<matt@mattwrock.com>)
3
- # Copyright:: Copyright (c) 2016 Chef Software, 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
- module ChefConfig
20
-
21
- def self.fips?
22
- if ChefConfig.windows?
23
- begin
24
- require "win32/registry"
25
- rescue LoadError
26
- return false
27
- end
28
-
29
- # from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
30
- reg_type =
31
- case ::RbConfig::CONFIG["target_cpu"]
32
- when "i386"
33
- Win32::Registry::KEY_READ | 0x100
34
- when "x86_64"
35
- Win32::Registry::KEY_READ | 0x200
36
- else
37
- Win32::Registry::KEY_READ
38
- end
39
- begin
40
- Win32::Registry::HKEY_LOCAL_MACHINE.open('System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy', reg_type) do |policy|
41
- policy["Enabled"] != 0
42
- end
43
- rescue Win32::Registry::Error
44
- false
45
- end
46
- else
47
- fips_path = "/proc/sys/crypto/fips_enabled"
48
- File.exist?(fips_path) && File.read(fips_path).chomp != "0"
49
- end
50
- end
51
- end
1
+ #
2
+ # Author:: Matt Wrock (<matt@mattwrock.com>)
3
+ # Copyright:: Copyright (c) 2016 Chef Software, 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
+ module ChefConfig
20
+
21
+ def self.fips?
22
+ if ChefConfig.windows?
23
+ begin
24
+ require "win32/registry"
25
+ rescue LoadError
26
+ return false
27
+ end
28
+
29
+ # from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
30
+ reg_type =
31
+ case ::RbConfig::CONFIG["target_cpu"]
32
+ when "i386"
33
+ Win32::Registry::KEY_READ | 0x100
34
+ when "x86_64"
35
+ Win32::Registry::KEY_READ | 0x200
36
+ else
37
+ Win32::Registry::KEY_READ
38
+ end
39
+ begin
40
+ Win32::Registry::HKEY_LOCAL_MACHINE.open('System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy', reg_type) do |policy|
41
+ policy["Enabled"] != 0
42
+ end
43
+ rescue Win32::Registry::Error
44
+ false
45
+ end
46
+ else
47
+ fips_path = "/proc/sys/crypto/fips_enabled"
48
+ File.exist?(fips_path) && File.read(fips_path).chomp != "0"
49
+ end
50
+ end
51
+ end
@@ -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
@@ -1,41 +1,41 @@
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
- if (!hostname.nil?) && (!matches.nil?)
25
- return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
26
- fuzzy_hostname_match?(hostname, m)
27
- end
28
- end
29
-
30
- false
31
- end
32
-
33
- def fuzzy_hostname_match?(hostname, match)
34
- # Do greedy matching by adding wildcard if it is not specified
35
- match = "*" + match if !match.start_with?("*")
36
- Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
37
- end
38
-
39
- end
40
- end
41
- 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 "fuzzyurl"
18
+
19
+ module ChefConfig
20
+ module Mixin
21
+ module FuzzyHostnameMatcher
22
+
23
+ def fuzzy_hostname_match_any?(hostname, matches)
24
+ if (!hostname.nil?) && (!matches.nil?)
25
+ return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
26
+ fuzzy_hostname_match?(hostname, m)
27
+ end
28
+ end
29
+
30
+ false
31
+ end
32
+
33
+ def fuzzy_hostname_match?(hostname, match)
34
+ # Do greedy matching by adding wildcard if it is not specified
35
+ match = "*" + match if !match.start_with?("*")
36
+ Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -1,272 +1,272 @@
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
- # Name of the gem being built. This is used to find the lines to fix in
35
- # Gemfile.lock.
36
- attr_accessor :gem_name
37
-
38
- # Should the generated version.rb be in a class or module? Default is false (module).
39
- attr_accessor :generate_version_class
40
-
41
- # Paths to the roots of any components that also support ChefPackageTask.
42
- # If relative paths are provided, they are rooted against root_path.
43
- attr_accessor :component_paths
44
-
45
- # This is the module name as it appears on the path "lib/module/".
46
- # e.g. for module_name "ChefDK", you'd want module_path to be "chef-dk".
47
- # The default is module_name but lower-cased.
48
- attr_writer :module_path
49
-
50
- def module_path
51
- @module_path || module_name.downcase
52
- end
53
-
54
- # Directory used to store package files and output that is generated.
55
- # This has the same meaning (or lack thereof) as package_dir in
56
- # rake/packagetask.
57
- attr_accessor :package_dir
58
-
59
- # Name of git remote used to push tags during a release. Default is origin.
60
- attr_accessor :git_remote
61
-
62
- def initialize(root_path = nil, module_name = nil, gem_name = nil)
63
- init(root_path, module_name, gem_name)
64
- yield self if block_given?
65
- define unless root_path.nil? || module_name.nil?
66
- end
67
-
68
- def init(root_path, module_name, gem_name)
69
- @root_path = root_path
70
- @module_name = module_name
71
- @gem_name = gem_name
72
- @component_paths = []
73
- @module_path = nil
74
- @package_dir = "pkg"
75
- @git_remote = "origin"
76
- @generate_version_class = false
77
- end
78
-
79
- def component_full_paths
80
- component_paths.map { |path| File.expand_path(path, root_path) }
81
- end
82
-
83
- def version_rb_path
84
- File.expand_path("lib/#{module_path}/version.rb", root_path)
85
- end
86
-
87
- def chef_root_path
88
- module_name == "Chef" ? root_path : File.dirname(root_path)
89
- end
90
-
91
- def version_file_path
92
- File.join(chef_root_path, "VERSION")
93
- end
94
-
95
- def gemfile_lock_path
96
- File.join(root_path, "Gemfile.lock")
97
- end
98
-
99
- def version
100
- IO.read(version_file_path).strip
101
- end
102
-
103
- def full_package_dir
104
- File.expand_path(package_dir, root_path)
105
- end
106
-
107
- def class_or_module
108
- generate_version_class ? "class" : "module"
109
- end
110
-
111
- def with_clean_env(&block)
112
- if defined?(Bundler)
113
- Bundler.with_clean_env(&block)
114
- else
115
- yield
116
- end
117
- end
118
-
119
- def define
120
- raise "Need to provide package root and module name" if root_path.nil? || module_name.nil?
121
-
122
- desc "Build Gems of component dependencies"
123
- task :package_components do
124
- component_full_paths.each do |component_path|
125
- Dir.chdir(component_path) do
126
- sh "rake package"
127
- end
128
- end
129
- end
130
-
131
- task :package => :package_components
132
-
133
- desc "Build and install component dependencies"
134
- task :install_components => :package_components do
135
- component_full_paths.each do |component_path|
136
- Dir.chdir(component_path) do
137
- sh "rake install"
138
- end
139
- end
140
- end
141
-
142
- task :install => :install_components
143
-
144
- desc "Clean up builds of component dependencies"
145
- task :clobber_component_packages do
146
- component_full_paths.each do |component_path|
147
- Dir.chdir(component_path) do
148
- sh "rake clobber_package"
149
- end
150
- end
151
- end
152
-
153
- task :clobber_package => :clobber_component_packages
154
-
155
- desc "Update the version number for component dependencies"
156
- task :update_components_versions do
157
- component_full_paths.each do |component_path|
158
- Dir.chdir(component_path) do
159
- sh "rake version"
160
- end
161
- end
162
- end
163
-
164
- namespace :version do
165
- desc 'Regenerate lib/#{@module_path}/version.rb from VERSION file'
166
- task :update => :update_components_versions do
167
- update_version_rb
168
- update_gemfile_lock
169
- end
170
-
171
- task :bump => %w{version:bump_patch version:update}
172
-
173
- task :show do
174
- puts version
175
- end
176
-
177
- # Add 1 to the current patch version in the VERSION file, and write it back out.
178
- task :bump_patch do
179
- current_version = version
180
- new_version = current_version.sub(/^(\d+\.\d+\.)(\d+)/) { "#{$1}#{$2.to_i + 1}" }
181
- puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
182
- IO.write(version_file_path, new_version)
183
- end
184
-
185
- def update_version_rb # rubocop:disable Lint/NestedMethodDefinition
186
- puts "Updating #{version_rb_path} to include version #{version} ..."
187
- contents = <<-VERSION_RB
188
- # Copyright:: Copyright 2010-2016, Chef Software, Inc.
189
- # License:: Apache License, Version 2.0
190
- #
191
- # Licensed under the Apache License, Version 2.0 (the "License");
192
- # you may not use this file except in compliance with the License.
193
- # You may obtain a copy of the License at
194
- #
195
- # http://www.apache.org/licenses/LICENSE-2.0
196
- #
197
- # Unless required by applicable law or agreed to in writing, software
198
- # distributed under the License is distributed on an "AS IS" BASIS,
199
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- # See the License for the specific language governing permissions and
201
- # limitations under the License.
202
-
203
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
204
- # NOTE: This file is generated by running `rake version` in the top level of
205
- # this repo. Do not edit this manually. Edit the VERSION file and run the rake
206
- # task instead.
207
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
208
-
209
- #{class_or_module} #{module_name}
210
- #{module_name.upcase}_ROOT = File.expand_path("../..", __FILE__)
211
- VERSION = "#{version}"
212
- end
213
-
214
- #
215
- # NOTE: the Chef::Version class is defined in version_class.rb
216
- #
217
- # NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
218
- # Chef::Version class is for _cookbooks_ only, and cannot handle
219
- # pre-release versions like "10.14.0.rc.2". Please use Rubygem's
220
- # Gem::Version class instead.
221
- #
222
- VERSION_RB
223
- IO.write(version_rb_path, contents)
224
- end
225
-
226
- def update_gemfile_lock # rubocop:disable Lint/NestedMethodDefinition
227
- if File.exist?(gemfile_lock_path)
228
- puts "Updating #{gemfile_lock_path} to include version #{version} ..."
229
- contents = IO.read(gemfile_lock_path)
230
- contents.gsub!(/^\s*(chef|chef-config)\s*\((= )?\S+\)\s*$/) do |line|
231
- line.gsub(/\((= )?\d+(\.\d+)+/) { "(#{$1}#{version}" }
232
- end
233
- IO.write(gemfile_lock_path, contents)
234
- end
235
- end
236
- end
237
-
238
- task :version => "version:update"
239
-
240
- gemspec_platform_to_install = ""
241
- Dir[File.expand_path("*.gemspec", root_path)].reverse_each do |gemspec_path|
242
- gemspec = eval(IO.read(gemspec_path))
243
- Gem::PackageTask.new(gemspec) do |task|
244
- task.package_dir = full_package_dir
245
- end
246
- gemspec_platform_to_install = "-#{gemspec.platform}" if gemspec.platform != Gem::Platform::RUBY && Gem::Platform.match(gemspec.platform)
247
- end
248
-
249
- desc "Build and install a #{module_path} gem"
250
- task :install => [:package] do
251
- with_clean_env do
252
- full_module_path = File.join(full_package_dir, module_path)
253
- sh %{gem install #{full_module_path}-#{version}#{gemspec_platform_to_install}.gem --no-rdoc --no-ri}
254
- end
255
- end
256
-
257
- task :uninstall do
258
- sh %{gem uninstall #{module_path} -x -v #{version} }
259
- end
260
-
261
- desc "Build it, tag it and ship it"
262
- task :ship => [:clobber_package, :gem] do
263
- sh("git tag #{version}")
264
- sh("git push #{git_remote} --tags")
265
- Dir[File.expand_path("*.gem", full_package_dir)].reverse_each do |built_gem|
266
- sh("gem push #{built_gem}")
267
- end
268
- end
269
- end
270
- end
271
-
272
- end
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
+ # Name of the gem being built. This is used to find the lines to fix in
35
+ # Gemfile.lock.
36
+ attr_accessor :gem_name
37
+
38
+ # Should the generated version.rb be in a class or module? Default is false (module).
39
+ attr_accessor :generate_version_class
40
+
41
+ # Paths to the roots of any components that also support ChefPackageTask.
42
+ # If relative paths are provided, they are rooted against root_path.
43
+ attr_accessor :component_paths
44
+
45
+ # This is the module name as it appears on the path "lib/module/".
46
+ # e.g. for module_name "ChefDK", you'd want module_path to be "chef-dk".
47
+ # The default is module_name but lower-cased.
48
+ attr_writer :module_path
49
+
50
+ def module_path
51
+ @module_path || module_name.downcase
52
+ end
53
+
54
+ # Directory used to store package files and output that is generated.
55
+ # This has the same meaning (or lack thereof) as package_dir in
56
+ # rake/packagetask.
57
+ attr_accessor :package_dir
58
+
59
+ # Name of git remote used to push tags during a release. Default is origin.
60
+ attr_accessor :git_remote
61
+
62
+ def initialize(root_path = nil, module_name = nil, gem_name = nil)
63
+ init(root_path, module_name, gem_name)
64
+ yield self if block_given?
65
+ define unless root_path.nil? || module_name.nil?
66
+ end
67
+
68
+ def init(root_path, module_name, gem_name)
69
+ @root_path = root_path
70
+ @module_name = module_name
71
+ @gem_name = gem_name
72
+ @component_paths = []
73
+ @module_path = nil
74
+ @package_dir = "pkg"
75
+ @git_remote = "origin"
76
+ @generate_version_class = false
77
+ end
78
+
79
+ def component_full_paths
80
+ component_paths.map { |path| File.expand_path(path, root_path) }
81
+ end
82
+
83
+ def version_rb_path
84
+ File.expand_path("lib/#{module_path}/version.rb", root_path)
85
+ end
86
+
87
+ def chef_root_path
88
+ module_name == "Chef" ? root_path : File.dirname(root_path)
89
+ end
90
+
91
+ def version_file_path
92
+ File.join(chef_root_path, "VERSION")
93
+ end
94
+
95
+ def gemfile_lock_path
96
+ File.join(root_path, "Gemfile.lock")
97
+ end
98
+
99
+ def version
100
+ IO.read(version_file_path).strip
101
+ end
102
+
103
+ def full_package_dir
104
+ File.expand_path(package_dir, root_path)
105
+ end
106
+
107
+ def class_or_module
108
+ generate_version_class ? "class" : "module"
109
+ end
110
+
111
+ def with_clean_env(&block)
112
+ if defined?(Bundler)
113
+ Bundler.with_clean_env(&block)
114
+ else
115
+ yield
116
+ end
117
+ end
118
+
119
+ def define
120
+ raise "Need to provide package root and module name" if root_path.nil? || module_name.nil?
121
+
122
+ desc "Build Gems of component dependencies"
123
+ task :package_components do
124
+ component_full_paths.each do |component_path|
125
+ Dir.chdir(component_path) do
126
+ sh "rake package"
127
+ end
128
+ end
129
+ end
130
+
131
+ task :package => :package_components
132
+
133
+ desc "Build and install component dependencies"
134
+ task :install_components => :package_components do
135
+ component_full_paths.each do |component_path|
136
+ Dir.chdir(component_path) do
137
+ sh "rake install"
138
+ end
139
+ end
140
+ end
141
+
142
+ task :install => :install_components
143
+
144
+ desc "Clean up builds of component dependencies"
145
+ task :clobber_component_packages do
146
+ component_full_paths.each do |component_path|
147
+ Dir.chdir(component_path) do
148
+ sh "rake clobber_package"
149
+ end
150
+ end
151
+ end
152
+
153
+ task :clobber_package => :clobber_component_packages
154
+
155
+ desc "Update the version number for component dependencies"
156
+ task :update_components_versions do
157
+ component_full_paths.each do |component_path|
158
+ Dir.chdir(component_path) do
159
+ sh "rake version"
160
+ end
161
+ end
162
+ end
163
+
164
+ namespace :version do
165
+ desc 'Regenerate lib/#{@module_path}/version.rb from VERSION file'
166
+ task :update => :update_components_versions do
167
+ update_version_rb
168
+ update_gemfile_lock
169
+ end
170
+
171
+ task :bump => %w{version:bump_patch version:update}
172
+
173
+ task :show do
174
+ puts version
175
+ end
176
+
177
+ # Add 1 to the current patch version in the VERSION file, and write it back out.
178
+ task :bump_patch do
179
+ current_version = version
180
+ new_version = current_version.sub(/^(\d+\.\d+\.)(\d+)/) { "#{$1}#{$2.to_i + 1}" }
181
+ puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
182
+ IO.write(version_file_path, new_version)
183
+ end
184
+
185
+ def update_version_rb # rubocop:disable Lint/NestedMethodDefinition
186
+ puts "Updating #{version_rb_path} to include version #{version} ..."
187
+ contents = <<-VERSION_RB
188
+ # Copyright:: Copyright 2010-2016, Chef Software, Inc.
189
+ # License:: Apache License, Version 2.0
190
+ #
191
+ # Licensed under the Apache License, Version 2.0 (the "License");
192
+ # you may not use this file except in compliance with the License.
193
+ # You may obtain a copy of the License at
194
+ #
195
+ # http://www.apache.org/licenses/LICENSE-2.0
196
+ #
197
+ # Unless required by applicable law or agreed to in writing, software
198
+ # distributed under the License is distributed on an "AS IS" BASIS,
199
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ # See the License for the specific language governing permissions and
201
+ # limitations under the License.
202
+
203
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
204
+ # NOTE: This file is generated by running `rake version` in the top level of
205
+ # this repo. Do not edit this manually. Edit the VERSION file and run the rake
206
+ # task instead.
207
+ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
208
+
209
+ #{class_or_module} #{module_name}
210
+ #{module_name.upcase}_ROOT = File.expand_path("../..", __FILE__)
211
+ VERSION = "#{version}"
212
+ end
213
+
214
+ #
215
+ # NOTE: the Chef::Version class is defined in version_class.rb
216
+ #
217
+ # NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
218
+ # Chef::Version class is for _cookbooks_ only, and cannot handle
219
+ # pre-release versions like "10.14.0.rc.2". Please use Rubygem's
220
+ # Gem::Version class instead.
221
+ #
222
+ VERSION_RB
223
+ IO.write(version_rb_path, contents)
224
+ end
225
+
226
+ def update_gemfile_lock # rubocop:disable Lint/NestedMethodDefinition
227
+ if File.exist?(gemfile_lock_path)
228
+ puts "Updating #{gemfile_lock_path} to include version #{version} ..."
229
+ contents = IO.read(gemfile_lock_path)
230
+ contents.gsub!(/^\s*(chef|chef-config)\s*\((= )?\S+\)\s*$/) do |line|
231
+ line.gsub(/\((= )?\d+(\.\d+)+/) { "(#{$1}#{version}" }
232
+ end
233
+ IO.write(gemfile_lock_path, contents)
234
+ end
235
+ end
236
+ end
237
+
238
+ task :version => "version:update"
239
+
240
+ gemspec_platform_to_install = ""
241
+ Dir[File.expand_path("*.gemspec", root_path)].reverse_each do |gemspec_path|
242
+ gemspec = eval(IO.read(gemspec_path))
243
+ Gem::PackageTask.new(gemspec) do |task|
244
+ task.package_dir = full_package_dir
245
+ end
246
+ gemspec_platform_to_install = "-#{gemspec.platform}" if gemspec.platform != Gem::Platform::RUBY && Gem::Platform.match(gemspec.platform)
247
+ end
248
+
249
+ desc "Build and install a #{module_path} gem"
250
+ task :install => [:package] do
251
+ with_clean_env do
252
+ full_module_path = File.join(full_package_dir, module_path)
253
+ sh %{gem install #{full_module_path}-#{version}#{gemspec_platform_to_install}.gem --no-rdoc --no-ri}
254
+ end
255
+ end
256
+
257
+ task :uninstall do
258
+ sh %{gem uninstall #{module_path} -x -v #{version} }
259
+ end
260
+
261
+ desc "Build it, tag it and ship it"
262
+ task :ship => [:clobber_package, :gem] do
263
+ sh("git tag #{version}")
264
+ sh("git push #{git_remote} --tags")
265
+ Dir[File.expand_path("*.gem", full_package_dir)].reverse_each do |built_gem|
266
+ sh("gem push #{built_gem}")
267
+ end
268
+ end
269
+ end
270
+ end
271
+
272
+ end