berkshelf 5.2.0 → 8.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +19 -47
  3. data/Rakefile +14 -4
  4. data/berkshelf.gemspec +61 -40
  5. data/bin/berks +2 -2
  6. data/lib/berkshelf/api-client.rb +1 -0
  7. data/lib/berkshelf/api_client/chef_server_connection.rb +29 -0
  8. data/lib/berkshelf/api_client/connection.rb +57 -0
  9. data/lib/berkshelf/api_client/errors.rb +10 -0
  10. data/lib/berkshelf/api_client/remote_cookbook.rb +56 -0
  11. data/lib/berkshelf/api_client/version.rb +5 -0
  12. data/lib/berkshelf/api_client.rb +24 -0
  13. data/lib/berkshelf/berksfile.rb +149 -122
  14. data/lib/berkshelf/cached_cookbook.rb +127 -24
  15. data/lib/berkshelf/chef_config_compat.rb +51 -0
  16. data/lib/berkshelf/chef_repo_universe.rb +47 -0
  17. data/lib/berkshelf/cli.rb +143 -174
  18. data/lib/berkshelf/commands/shelf.rb +20 -19
  19. data/lib/berkshelf/community_rest.rb +59 -94
  20. data/lib/berkshelf/config.rb +97 -127
  21. data/lib/berkshelf/cookbook_store.rb +7 -6
  22. data/lib/berkshelf/core_ext/file.rb +1 -1
  23. data/lib/berkshelf/core_ext/file_utils.rb +4 -4
  24. data/lib/berkshelf/core_ext.rb +1 -1
  25. data/lib/berkshelf/dependency.rb +25 -32
  26. data/lib/berkshelf/downloader.rb +66 -39
  27. data/lib/berkshelf/errors.rb +23 -17
  28. data/lib/berkshelf/file_syncer.rb +24 -47
  29. data/lib/berkshelf/formatters/human.rb +7 -5
  30. data/lib/berkshelf/formatters/json.rb +6 -6
  31. data/lib/berkshelf/installer.rb +120 -111
  32. data/lib/berkshelf/location.rb +14 -14
  33. data/lib/berkshelf/locations/base.rb +1 -1
  34. data/lib/berkshelf/locations/git.rb +16 -24
  35. data/lib/berkshelf/locations/github.rb +2 -2
  36. data/lib/berkshelf/locations/path.rb +2 -2
  37. data/lib/berkshelf/lockfile.rb +326 -328
  38. data/lib/berkshelf/logger.rb +64 -1
  39. data/lib/berkshelf/mixin/git.rb +6 -5
  40. data/lib/berkshelf/packager.rb +44 -10
  41. data/lib/berkshelf/resolver/graph.rb +1 -1
  42. data/lib/berkshelf/resolver.rb +4 -4
  43. data/lib/berkshelf/ridley_compat.rb +109 -0
  44. data/lib/berkshelf/shell.rb +2 -1
  45. data/lib/berkshelf/shell_out.rb +18 -0
  46. data/lib/berkshelf/source.rb +77 -33
  47. data/lib/berkshelf/source_uri.rb +4 -4
  48. data/lib/berkshelf/ssl_policies.rb +38 -0
  49. data/lib/berkshelf/thor.rb +1 -1
  50. data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
  51. data/lib/berkshelf/thor_ext.rb +1 -1
  52. data/lib/berkshelf/uploader.rb +106 -70
  53. data/lib/berkshelf/validator.rb +13 -5
  54. data/lib/berkshelf/version.rb +1 -1
  55. data/lib/berkshelf/visualizer.rb +16 -11
  56. data/lib/berkshelf.rb +106 -81
  57. data/spec/config/knife.rb +4 -4
  58. data/spec/data/trusted_certs/example.crt +22 -0
  59. data/spec/fixtures/Berksfile +3 -3
  60. data/spec/fixtures/complex-cookbook-path/cookbooks/app/metadata.rb +2 -0
  61. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins/metadata.rb +2 -0
  62. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins-config/metadata.rb +4 -0
  63. data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
  64. data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
  65. data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
  66. data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
  67. data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
  68. data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
  69. data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
  70. data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
  71. data/spec/fixtures/cookbook-store/jenkins-2.0.3/metadata.rb +5 -5
  72. data/spec/fixtures/cookbook-store/jenkins-2.0.4/metadata.rb +4 -4
  73. data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
  74. data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -3
  75. data/spec/spec_helper.rb +56 -64
  76. data/spec/support/chef_api.rb +15 -16
  77. data/spec/support/chef_server.rb +71 -69
  78. data/spec/support/git.rb +59 -58
  79. data/spec/support/kitchen.rb +0 -14
  80. data/spec/support/matchers/file_system_matchers.rb +4 -5
  81. data/spec/support/matchers/filepath_matchers.rb +2 -2
  82. data/spec/support/path_helpers.rb +17 -17
  83. data/spec/support/shared_examples/formatter.rb +1 -1
  84. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
  85. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
  86. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
  87. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
  88. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
  89. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
  90. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
  91. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
  92. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
  93. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
  94. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
  95. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
  96. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
  97. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
  98. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
  99. data/spec/unit/berkshelf/berksfile_spec.rb +84 -105
  100. data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
  101. data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +157 -0
  102. data/spec/unit/berkshelf/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  103. data/spec/unit/berkshelf/berkshelf/api_client_spec.rb +9 -0
  104. data/spec/unit/berkshelf/cached_cookbook_spec.rb +45 -47
  105. data/spec/unit/berkshelf/chef_repo_universe_spec.rb +37 -0
  106. data/spec/unit/berkshelf/cli_spec.rb +7 -8
  107. data/spec/unit/berkshelf/community_rest_spec.rb +82 -90
  108. data/spec/unit/berkshelf/config_spec.rb +51 -22
  109. data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
  110. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +7 -8
  111. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
  112. data/spec/unit/berkshelf/dependency_spec.rb +48 -48
  113. data/spec/unit/berkshelf/downloader_spec.rb +191 -34
  114. data/spec/unit/berkshelf/errors_spec.rb +3 -3
  115. data/spec/unit/berkshelf/file_syncer_spec.rb +87 -87
  116. data/spec/unit/berkshelf/formatters/base_spec.rb +23 -23
  117. data/spec/unit/berkshelf/formatters/human_spec.rb +2 -2
  118. data/spec/unit/berkshelf/formatters/json_spec.rb +2 -2
  119. data/spec/unit/berkshelf/formatters/null_spec.rb +3 -3
  120. data/spec/unit/berkshelf/installer_spec.rb +8 -8
  121. data/spec/unit/berkshelf/location_spec.rb +11 -11
  122. data/spec/unit/berkshelf/locations/base_spec.rb +35 -36
  123. data/spec/unit/berkshelf/locations/git_spec.rb +90 -93
  124. data/spec/unit/berkshelf/locations/path_spec.rb +40 -41
  125. data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
  126. data/spec/unit/berkshelf/lockfile_spec.rb +205 -211
  127. data/spec/unit/berkshelf/logger_spec.rb +3 -3
  128. data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -5
  129. data/spec/unit/berkshelf/packager_spec.rb +2 -2
  130. data/spec/unit/berkshelf/resolver/graph_spec.rb +10 -8
  131. data/spec/unit/berkshelf/resolver_spec.rb +17 -17
  132. data/spec/unit/berkshelf/ridley_compat_spec.rb +16 -0
  133. data/spec/unit/berkshelf/shell_spec.rb +34 -34
  134. data/spec/unit/berkshelf/source_spec.rb +186 -20
  135. data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
  136. data/spec/unit/berkshelf/ssl_policies_spec.rb +86 -0
  137. data/spec/unit/berkshelf/uploader_spec.rb +146 -64
  138. data/spec/unit/berkshelf/validator_spec.rb +23 -16
  139. data/spec/unit/berkshelf/visualizer_spec.rb +24 -15
  140. data/spec/unit/berkshelf_spec.rb +18 -18
  141. metadata +138 -289
  142. data/.gitignore +0 -29
  143. data/.travis.yml +0 -64
  144. data/CHANGELOG.legacy.md +0 -307
  145. data/CHANGELOG.md +0 -1358
  146. data/CONTRIBUTING.md +0 -64
  147. data/Gemfile.lock +0 -399
  148. data/Guardfile +0 -23
  149. data/PLUGINS.md +0 -25
  150. data/README.md +0 -70
  151. data/Thorfile +0 -61
  152. data/appveyor.yml +0 -31
  153. data/docs/berkshelf_for_newcomers.md +0 -65
  154. data/features/berksfile.feature +0 -46
  155. data/features/commands/apply.feature +0 -41
  156. data/features/commands/contingent.feature +0 -48
  157. data/features/commands/cookbook.feature +0 -35
  158. data/features/commands/info.feature +0 -99
  159. data/features/commands/init.feature +0 -27
  160. data/features/commands/install.feature +0 -636
  161. data/features/commands/list.feature +0 -78
  162. data/features/commands/outdated.feature +0 -130
  163. data/features/commands/package.feature +0 -17
  164. data/features/commands/search.feature +0 -17
  165. data/features/commands/shelf/list.feature +0 -32
  166. data/features/commands/shelf/show.feature +0 -143
  167. data/features/commands/shelf/uninstall.feature +0 -96
  168. data/features/commands/show.feature +0 -83
  169. data/features/commands/update.feature +0 -142
  170. data/features/commands/upload.feature +0 -426
  171. data/features/commands/vendor.feature +0 -111
  172. data/features/commands/verify.feature +0 -29
  173. data/features/commands/viz.feature +0 -66
  174. data/features/community_site.feature +0 -37
  175. data/features/config.feature +0 -111
  176. data/features/help.feature +0 -11
  177. data/features/json_formatter.feature +0 -161
  178. data/features/lifecycle.feature +0 -378
  179. data/features/lockfile.feature +0 -378
  180. data/features/step_definitions/berksfile_steps.rb +0 -39
  181. data/features/step_definitions/chef/config_steps.rb +0 -12
  182. data/features/step_definitions/chef_server_steps.rb +0 -60
  183. data/features/step_definitions/cli_steps.rb +0 -18
  184. data/features/step_definitions/config_steps.rb +0 -46
  185. data/features/step_definitions/environment_steps.rb +0 -7
  186. data/features/step_definitions/filesystem_steps.rb +0 -269
  187. data/features/step_definitions/gem_steps.rb +0 -13
  188. data/features/step_definitions/json_steps.rb +0 -23
  189. data/features/step_definitions/utility_steps.rb +0 -11
  190. data/features/support/aruba.rb +0 -12
  191. data/features/support/env.rb +0 -82
  192. data/generator_files/Berksfile.erb +0 -11
  193. data/generator_files/CHANGELOG.md.erb +0 -3
  194. data/generator_files/Gemfile.erb +0 -8
  195. data/generator_files/README.md.erb +0 -42
  196. data/generator_files/Thorfile.erb +0 -11
  197. data/generator_files/Vagrantfile.erb +0 -117
  198. data/generator_files/chefignore +0 -94
  199. data/generator_files/default_recipe.erb +0 -6
  200. data/generator_files/default_test.rb.erb +0 -11
  201. data/generator_files/gitignore.erb +0 -23
  202. data/generator_files/helpers.rb.erb +0 -7
  203. data/generator_files/licenses/apachev2.erb +0 -13
  204. data/generator_files/licenses/gplv2.erb +0 -15
  205. data/generator_files/licenses/gplv3.erb +0 -14
  206. data/generator_files/licenses/mit.erb +0 -20
  207. data/generator_files/licenses/reserved.erb +0 -3
  208. data/generator_files/metadata.rb.erb +0 -11
  209. data/lib/berkshelf/base_generator.rb +0 -43
  210. data/lib/berkshelf/commands/test_command.rb +0 -13
  211. data/lib/berkshelf/cookbook_generator.rb +0 -133
  212. data/lib/berkshelf/init_generator.rb +0 -195
  213. data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
  214. data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
  215. data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -110
  216. data/spec/unit/berkshelf/init_generator_spec.rb +0 -263
@@ -1,94 +0,0 @@
1
- # Put files/directories that should be ignored in this file when uploading
2
- # or sharing to the community site.
3
- # Lines that start with '# ' are comments.
4
-
5
- # OS generated files #
6
- ######################
7
- .DS_Store
8
- Icon?
9
- nohup.out
10
- ehthumbs.db
11
- Thumbs.db
12
-
13
- # SASS #
14
- ########
15
- .sass-cache
16
-
17
- # EDITORS #
18
- ###########
19
- \#*
20
- .#*
21
- *~
22
- *.sw[a-z]
23
- *.bak
24
- REVISION
25
- TAGS*
26
- tmtags
27
- *_flymake.*
28
- *_flymake
29
- *.tmproj
30
- .project
31
- .settings
32
- mkmf.log
33
-
34
- ## COMPILED ##
35
- ##############
36
- a.out
37
- *.o
38
- *.pyc
39
- *.so
40
- *.com
41
- *.class
42
- *.dll
43
- *.exe
44
- */rdoc/
45
-
46
- # Testing #
47
- ###########
48
- .watchr
49
- .rspec
50
- spec/*
51
- spec/fixtures/*
52
- test/*
53
- features/*
54
- Guardfile
55
- Procfile
56
-
57
- # SCM #
58
- #######
59
- .git
60
- */.git
61
- .gitignore
62
- .gitmodules
63
- .gitconfig
64
- .gitattributes
65
- .svn
66
- */.bzr/*
67
- */.hg/*
68
- */.svn/*
69
-
70
- # Berkshelf #
71
- #############
72
- cookbooks/*
73
- tmp
74
-
75
- # Cookbooks #
76
- #############
77
- CONTRIBUTING
78
- CHANGELOG*
79
-
80
- # Strainer #
81
- ############
82
- Colanderfile
83
- Strainerfile
84
- .colander
85
- .strainer
86
-
87
- # Vagrant #
88
- ###########
89
- .vagrant
90
- Vagrantfile
91
-
92
- # Travis #
93
- ##########
94
- .travis.yml
@@ -1,6 +0,0 @@
1
- #
2
- # Cookbook Name:: <%= name %>
3
- # Recipe:: default
4
- #
5
- <%= commented(license) %>
6
- #
@@ -1,11 +0,0 @@
1
- require File.expand_path('../support/helpers', __FILE__)
2
-
3
- describe '<%= cookbook_name %>::default' do
4
-
5
- include Helpers::<%= cookbook_name.capitalize.gsub('-','_') %>
6
-
7
- # Example spec tests can be found at http://git.io/Fahwsw
8
- it 'runs no tests by default' do
9
- end
10
-
11
- end
@@ -1,23 +0,0 @@
1
- *~
2
- *#
3
- .#*
4
- \#*#
5
- .*.sw[a-z]
6
- *.un~
7
- pkg/
8
-
9
- # Berkshelf
10
- .vagrant
11
- /cookbooks
12
- <% unless options[:pattern] == "environment" -%>
13
- Berksfile.lock
14
- <% end -%>
15
-
16
- # Bundler
17
- Gemfile.lock
18
- bin/*
19
- .bundle/*
20
-
21
- <% if options[:scmversion] -%>
22
- VERSION
23
- <% end -%>
@@ -1,7 +0,0 @@
1
- module Helpers
2
- module <%= cookbook_name.capitalize.gsub('-','_') %>
3
- include MiniTest::Chef::Assertions
4
- include MiniTest::Chef::Context
5
- include MiniTest::Chef::Resources
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- Copyright (C) <%= copyright_year %> <%= maintainer %>
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
@@ -1,15 +0,0 @@
1
- Copyright (C) <%= copyright_year %> <%= maintainer %>
2
-
3
- This program is free software; you can redistribute it and/or modify
4
- it under the terms of the GNU General Public License as published by
5
- the Free Software Foundation; either version 2 of the License, or
6
- (at your option) any later version.
7
-
8
- This program is distributed in the hope that it will be useful,
9
- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- GNU General Public License for more details.
12
-
13
- You should have received a copy of the GNU General Public License along
14
- with this program; if not, write to the Free Software Foundation, Inc.,
15
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
@@ -1,14 +0,0 @@
1
- Copyright (C) <%= copyright_year %> <%= maintainer %>
2
-
3
- This program is free software: you can redistribute it and/or modify
4
- it under the terms of the GNU General Public License as published by
5
- the Free Software Foundation, either version 3 of the License, or
6
- (at your option) any later version.
7
-
8
- This program is distributed in the hope that it will be useful,
9
- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- GNU General Public License for more details.
12
-
13
- You should have received a copy of the GNU General Public License
14
- along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -1,20 +0,0 @@
1
- Copyright (C) <%= copyright_year %> <%= maintainer %>
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,3 +0,0 @@
1
- Copyright (C) <%= copyright_year %> <%= maintainer %>
2
-
3
- All rights reserved - Do Not Redistribute
@@ -1,11 +0,0 @@
1
- name '<%= name %>'
2
- maintainer '<%= maintainer %>'
3
- maintainer_email '<%= maintainer_email %>'
4
- license '<%= license_name %>'
5
- description 'Installs/Configures <%= name %>'
6
- long_description 'Installs/Configures <%= name %>'
7
- <% if options[:scmversion] -%>
8
- version IO.read(File.join(File.dirname(__FILE__), 'VERSION'))
9
- <% else -%>
10
- version '0.1.0'
11
- <% end -%>
@@ -1,43 +0,0 @@
1
- require 'thor/group'
2
-
3
- module Berkshelf
4
- class BaseGenerator < Thor::Group
5
- class << self
6
- def source_root
7
- Berkshelf.root.join('generator_files')
8
- end
9
- end
10
-
11
- # A list of cookbook patterns accepted by generators inheriting from
12
- # this generator.
13
- #
14
- # @return [Array<String>]
15
- PATTERNS = [
16
- "environment",
17
- "application",
18
- "library",
19
- "wrapper"
20
- ].freeze
21
-
22
- shell = Berkshelf.ui
23
-
24
- argument :path,
25
- type: :string,
26
- required: true
27
-
28
- class_option :pattern,
29
- type: :string,
30
- default: "application",
31
- desc: "Modifies the generated skeleton based on the given pattern.",
32
- aliases: "-p",
33
- enum: BaseGenerator::PATTERNS
34
-
35
- include Thor::Actions
36
-
37
- private
38
-
39
- def target
40
- @target ||= Pathname.new(File.expand_path(path))
41
- end
42
- end
43
- end
@@ -1,13 +0,0 @@
1
- begin
2
- require 'kitchen/cli'
3
- rescue LoadError; end
4
-
5
- module Berkshelf
6
- class TestCommand < Kitchen::CLI
7
- namespace "test"
8
- end
9
-
10
- class Cli < Thor
11
- register(Berkshelf::TestCommand, 'test', 'test [COMMAND]', 'Testing tasks for your cookbook', hide: true)
12
- end
13
- end if defined?(Kitchen::CLI)
@@ -1,133 +0,0 @@
1
- module Berkshelf
2
- class CookbookGenerator < BaseGenerator
3
- require_relative 'config'
4
-
5
- LICENSE_MAP = {
6
- "apachev2" => "Apache 2.0",
7
- "gplv2" => "GNU Public License 2.0",
8
- "gplv3" => "GNU Public License 3.0",
9
- "mit" => "MIT",
10
- "reserved" => "All rights reserved",
11
- }.freeze
12
-
13
- (LICENSES = LICENSE_MAP.keys).freeze
14
-
15
- argument :name,
16
- type: :string,
17
- required: true
18
-
19
- class_option :skip_vagrant,
20
- type: :boolean,
21
- default: false
22
-
23
- class_option :skip_git,
24
- type: :boolean,
25
- default: false
26
-
27
- class_option :skip_test_kitchen,
28
- type: :boolean,
29
- default: false,
30
- desc: 'Skip adding a testing environment to your cookbook'
31
-
32
- class_option :foodcritic,
33
- type: :boolean,
34
- default: false
35
-
36
- class_option :chef_minitest,
37
- type: :boolean,
38
- default: false
39
-
40
- class_option :scmversion,
41
- type: :boolean,
42
- default: false
43
-
44
- class_option :no_bundler,
45
- type: :boolean,
46
- default: false
47
-
48
- class_option :license,
49
- type: :string,
50
- default: Berkshelf.config.cookbook.license
51
-
52
- class_option :maintainer,
53
- type: :string,
54
- default: Berkshelf.config.cookbook.copyright
55
-
56
- class_option :maintainer_email,
57
- type: :string,
58
- default: Berkshelf.config.cookbook.email
59
-
60
- def generate
61
- case options[:pattern]
62
- when "library"
63
- empty_directory target.join("libraries")
64
- empty_directory target.join("providers")
65
- empty_directory target.join("resources")
66
- when "wrapper"
67
- empty_directory target.join("attributes")
68
- empty_directory target.join("recipes")
69
- template "default_recipe.erb", target.join("recipes/default.rb")
70
- when "environment", "application"
71
- empty_directory target.join("files/default")
72
- empty_directory target.join("templates/default")
73
- empty_directory target.join("attributes")
74
- empty_directory target.join("libraries")
75
- empty_directory target.join("providers")
76
- empty_directory target.join("recipes")
77
- empty_directory target.join("resources")
78
- template "default_recipe.erb", target.join("recipes/default.rb")
79
- end
80
-
81
- template 'metadata.rb.erb', target.join('metadata.rb')
82
- template license_file, target.join('LICENSE')
83
- template 'README.md.erb', target.join('README.md')
84
- template 'CHANGELOG.md.erb', target.join('CHANGELOG.md')
85
-
86
- Berkshelf::InitGenerator.new([target], options.merge(default_options)).invoke_all
87
- end
88
-
89
- private
90
-
91
- def commented(content)
92
- content.split("\n").collect { |s| s == "" ? "#" : "# #{s}"}.join("\n")
93
- end
94
-
95
- def license_name
96
- LICENSE_MAP.fetch(options[:license]) do |license|
97
- raise Berkshelf::LicenseNotFound.new(license)
98
- end
99
- end
100
-
101
- def license
102
- ERB.new(File.read(File.join(self.class.source_root, license_file))).result(binding)
103
- end
104
-
105
- def license_file
106
- case options[:license]
107
- when 'apachev2'; 'licenses/apachev2.erb'
108
- when 'gplv2'; 'licenses/gplv2.erb'
109
- when 'gplv3'; 'licenses/gplv3.erb'
110
- when 'mit'; 'licenses/mit.erb'
111
- when 'reserved'; 'licenses/reserved.erb'
112
- else
113
- raise Berkshelf::LicenseNotFound.new(options[:license])
114
- end
115
- end
116
-
117
- def copyright_year
118
- Time.now.year
119
- end
120
-
121
- def maintainer
122
- options[:maintainer]
123
- end
124
-
125
- def maintainer_email
126
- options[:maintainer_email]
127
- end
128
-
129
- def default_options
130
- { metadata_entry: true, chefignore: true, cookbook_name: name }
131
- end
132
- end
133
- end
@@ -1,195 +0,0 @@
1
- begin
2
- require 'kitchen/generator/init'
3
- rescue LoadError; end
4
-
5
- module Berkshelf
6
- class InitGenerator < BaseGenerator
7
- include Mixin::Git
8
-
9
- def initialize(*args)
10
- super(*args)
11
- if @options[:cookbook_name]
12
- @cookbook_name = @options[:cookbook_name]
13
- end
14
- end
15
-
16
- class_option :metadata_entry,
17
- type: :boolean,
18
- default: true
19
-
20
- class_option :chefignore,
21
- type: :boolean,
22
- default: true
23
-
24
- class_option :skip_vagrant,
25
- type: :boolean,
26
- default: false,
27
- desc: 'Skips adding a Vagrantfile and adding supporting gems to the Gemfile'
28
-
29
- class_option :skip_git,
30
- type: :boolean,
31
- default: false,
32
- desc: 'Skips adding a .gitignore and running git init in the cookbook directory'
33
-
34
- class_option :foodcritic,
35
- type: :boolean,
36
- default: false,
37
- desc: 'Creates a Thorfile with Foodcritic support to lint test your cookbook'
38
-
39
- class_option :chef_minitest,
40
- type: :boolean,
41
- default: false
42
-
43
- class_option :scmversion,
44
- type: :boolean,
45
- default: false,
46
- desc: 'Creates a Thorfile with SCMVersion support to manage versions for continuous integration'
47
-
48
- class_option :no_bundler,
49
- type: :boolean,
50
- default: false,
51
- desc: 'Skips generation of a Gemfile and other Bundler specific support'
52
-
53
- class_option :cookbook_name,
54
- type: :string
55
-
56
- if defined?(Kitchen::Generator::Init)
57
- class_option :skip_test_kitchen,
58
- type: :boolean,
59
- default: false,
60
- desc: 'Skip adding a testing environment to your cookbook'
61
- end
62
-
63
- def generate
64
- validate_cookbook
65
- validate_configuration
66
- check_option_support
67
-
68
- template 'Berksfile.erb', target.join('Berksfile')
69
- template 'Thorfile.erb', target.join('Thorfile')
70
-
71
- if options[:chefignore]
72
- copy_file 'chefignore', target.join(Ridley::Chef::Chefignore::FILENAME)
73
- end
74
-
75
- unless options[:skip_git]
76
- template 'gitignore.erb', target.join('.gitignore')
77
-
78
- unless File.exists?(target.join('.git'))
79
- inside target do
80
- git 'init'
81
- end
82
- end
83
- end
84
-
85
- if options[:chef_minitest]
86
- empty_directory target.join('files/default/tests/minitest/support')
87
- template 'default_test.rb.erb', target.join('files/default/tests/minitest/default_test.rb')
88
- template 'helpers.rb.erb', target.join('files/default/tests/minitest/support/helpers.rb')
89
- end
90
-
91
- if options[:scmversion]
92
- create_file target.join('VERSION'), '0.1.0'
93
- end
94
-
95
- unless options[:no_bundler]
96
- template 'Gemfile.erb', target.join('Gemfile')
97
- end
98
-
99
- if defined?(Kitchen::Generator::Init)
100
- unless options[:skip_test_kitchen]
101
- Kitchen::Generator::Init.new([], {}, destination_root: target).invoke_all
102
- end
103
- end
104
-
105
- unless options[:skip_vagrant]
106
- template 'Vagrantfile.erb', target.join('Vagrantfile')
107
- end
108
- end
109
-
110
- private
111
-
112
- def berkshelf_config
113
- Berkshelf.config
114
- end
115
-
116
- # Read the cookbook name from the metadata.rb
117
- #
118
- # @return [String]
119
- # name of the cookbook
120
- def cookbook_name
121
- @cookbook_name ||= begin
122
- metadata = Ridley::Chef::Cookbook::Metadata.from_file(target.join('metadata.rb').to_s)
123
- metadata.name.empty? ? File.basename(target) : metadata.name
124
- rescue CookbookNotFound, IOError
125
- File.basename(target)
126
- end
127
- end
128
-
129
- # Assert the current working directory is a cookbook
130
- #
131
- # @raise [NotACookbook] if the current working directory is
132
- # not a cookbook
133
- #
134
- # @return [nil]
135
- def validate_cookbook
136
- path = File.expand_path(File.join(target, 'metadata.rb'))
137
- unless File.exists?(path)
138
- raise Berkshelf::NotACookbook.new(path)
139
- end
140
- end
141
-
142
- # Assert valid configuration
143
- #
144
- # @raise [InvalidConfiguration] if the configuration is invalid
145
- #
146
- # @return [nil]
147
- def validate_configuration
148
- unless Berkshelf.config.valid?
149
- raise InvalidConfiguration.new(Berkshelf.config.errors)
150
- end
151
- end
152
-
153
- # Check for supporting gems for provided options
154
- #
155
- # @return [Boolean]
156
- def check_option_support
157
- assert_option_supported(:foodcritic) &&
158
- assert_option_supported(:scmversion, 'thor-scmversion') &&
159
- assert_default_supported(:no_bundler, 'bundler')
160
- end
161
-
162
- # Warn if the supporting gem for an option is not installed
163
- #
164
- # @return [Boolean]
165
- def assert_option_supported(option, gem_name = option.to_s)
166
- if options[option]
167
- begin
168
- Gem::Specification.find_by_name(gem_name)
169
- rescue Gem::LoadError
170
- Berkshelf.ui.warn "This cookbook was generated with --#{option}, however, #{gem_name} is not installed."
171
- Berkshelf.ui.warn "To make use of --#{option}: gem install #{gem_name}"
172
- return false
173
- end
174
- end
175
- true
176
- end
177
-
178
- # Warn if the supporting gem for a default is not installed
179
- #
180
- # @return [Boolean]
181
- def assert_default_supported(option, gem_name = option.to_s)
182
- unless options[option]
183
- begin
184
- Gem::Specification.find_by_name(gem_name)
185
- rescue Gem::LoadError
186
- Berkshelf.ui.warn "By default, this cookbook was generated to support #{gem_name}, however, #{gem_name} is not installed."
187
- Berkshelf.ui.warn "To skip support for #{gem_name}, use --#{option.to_s.gsub('_', '-')}"
188
- Berkshelf.ui.warn "To install #{gem_name}: gem install #{gem_name}"
189
- return false
190
- end
191
- end
192
- true
193
- end
194
- end
195
- end
@@ -1,2 +0,0 @@
1
- .kitchen/
2
- .kitchen.local.yml
@@ -1,26 +0,0 @@
1
- ---
2
- driver_plugin: vagrant
3
-
4
- platforms:
5
- - name: ubuntu-12.04
6
- driver_config:
7
- box: canonical-ubuntu-12.04
8
- box_url: http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box
9
- require_chef_omnibus: true
10
- - name: ubuntu-10.04
11
- driver_config:
12
- box: opscode-ubuntu-10.04
13
- box_url: http://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_chef-11.2.0.box
14
- - name: centos-6.3
15
- driver_config:
16
- box: opscode-centos-6.3
17
- box_url: http://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.3_chef-11.2.0.box
18
- - name: centos-5.8
19
- driver_config:
20
- box: opscode-centos-5.8
21
- box_url: http://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-5.8_chef-11.2.0.box
22
-
23
- suites:
24
- - name: default
25
- run_list: []
26
- attributes: {}