power_stencil 0.4.22 → 0.5.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/doc/plugins.md +269 -18
  3. data/etc/meta_templates/plugin_seed/etc/command_line.yaml +1 -1
  4. data/etc/meta_templates/plugin_seed/etc/plugin_capabilities.yaml +33 -0
  5. data/etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/.copy_ignore +2 -0
  6. data/etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/.subst_ignore +1 -0
  7. data/etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/message.txt +7 -0
  8. data/etc/meta_templates/plugin_seed/lib/{entity}.rb.erb +9 -24
  9. data/etc/meta_templates/plugin_seed/lib/{entity}/dsl/{entity}_dsl.rb.erb +9 -0
  10. data/etc/meta_templates/plugin_seed/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +2 -0
  11. data/etc/meta_templates/plugin_seed/lib/{entity}/{entity}_processor.rb.erb +4 -1
  12. data/etc/templates/plugin_definition/.travis.yml +1 -1
  13. data/etc/templates/plugin_definition/CODE_OF_CONDUCT.md +1 -1
  14. data/etc/templates/plugin_definition/etc/command_line.yaml +1 -1
  15. data/etc/templates/plugin_definition/etc/plugin_capabilities.yaml +33 -0
  16. data/etc/templates/plugin_definition/etc/plugin_config.yaml +1 -1
  17. data/etc/templates/plugin_definition/etc/templates/{entity}_entity/.copy_ignore +2 -0
  18. data/etc/templates/plugin_definition/etc/templates/{entity}_entity/.subst_ignore +1 -0
  19. data/etc/templates/plugin_definition/etc/templates/{entity}_entity/message.txt +7 -0
  20. data/etc/templates/plugin_definition/lib/{entity}.rb.erb +9 -24
  21. data/etc/templates/plugin_definition/lib/{entity}/dsl/{entity}_dsl.rb.erb +9 -0
  22. data/etc/templates/plugin_definition/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +2 -0
  23. data/etc/templates/plugin_definition/lib/{entity}/{entity}_processor.rb.erb +4 -1
  24. data/lib/power_stencil/command_processors/info.rb +0 -3
  25. data/lib/power_stencil/dsl/plugin_generation.rb +9 -0
  26. data/lib/power_stencil/engine/build_handling.rb +12 -7
  27. data/lib/power_stencil/engine/project_engine.rb +13 -9
  28. data/lib/power_stencil/plugins/base.rb +20 -5
  29. data/lib/power_stencil/plugins/build.rb +17 -0
  30. data/lib/power_stencil/plugins/capabilities.rb +24 -15
  31. data/lib/power_stencil/plugins/command_line.rb +13 -1
  32. data/lib/power_stencil/plugins/config.rb +11 -15
  33. data/lib/power_stencil/plugins/dsl.rb +17 -0
  34. data/lib/power_stencil/plugins/entity_definitions.rb +17 -0
  35. data/lib/power_stencil/plugins/require.rb +1 -31
  36. data/lib/power_stencil/plugins/templates.rb +10 -8
  37. data/lib/power_stencil/plugins/type.rb +13 -0
  38. data/lib/power_stencil/project/config.rb +2 -2
  39. data/lib/power_stencil/project/paths.rb +3 -0
  40. data/lib/power_stencil/project/plugins.rb +3 -14
  41. data/lib/power_stencil/utils/secure_require.rb +1 -1
  42. data/lib/power_stencil/version.rb +1 -1
  43. metadata +21 -9
  44. data/lib/power_stencil/plugins/dependencies.rb +0 -32
@@ -3,27 +3,23 @@ module PowerStencil
3
3
 
4
4
  module Config
5
5
 
6
- attr_reader :plugin_specific_config
7
-
8
- def has_plugin_specific_config?
9
- yaml_file = project.plugin_config_specific_file(name)
10
- if File.exists? yaml_file and File.file? yaml_file and File.readable? yaml_file
11
- logger.info "Found plugin specific config to global config from '#{name}' plugin..."
12
- return true
13
- end
14
- logger.debug "There is no extra command line definition provided by plugin '#{name}'."
15
- false
6
+ def plugin_config_specific_file
7
+ project.plugin_config_specific_file self.name
16
8
  end
17
9
 
10
+ private
11
+
18
12
  def load_plugin_specific_config
19
- yaml_file = project.plugin_config_specific_file(name)
20
- if has_plugin_specific_config?
21
- project.add_plugin_config(name)
22
- capabilities[:local_config] = true
13
+ yaml_file = plugin_config_specific_file
14
+ if File.exists? yaml_file and File.file? yaml_file and File.readable? yaml_file
15
+ logger.info "Found plugin specific config in plugin '#{self.name}'. Attempting to load..."
16
+ project.add_plugin_config self.name
17
+ capabilities[:config] = true
23
18
  end
24
19
  rescue => e
25
20
  logger.debug PowerStencil::Error.report_error(e)
26
- logger.warn "Could not load yaml file '#{yaml_file}' because '#{e.message}'"
21
+ logger.error "Could not load yaml file '#{yaml_file}' because '#{e.message}'"
22
+ raise e
27
23
  end
28
24
 
29
25
  end
@@ -0,0 +1,17 @@
1
+ module PowerStencil
2
+ module Plugins
3
+
4
+ module Dsl
5
+
6
+ def require_plugin_dsl
7
+ return unless capabilities[:dsl]
8
+ logger.info "Requiring '#{self.name}' DSL addon definition..."
9
+ plugin_definition[:dsl].each do |dsl_definition_file_path|
10
+ securely_require dsl_definition_file_path, fail_on_error: true
11
+ end
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ module PowerStencil
2
+ module Plugins
3
+
4
+ module EntityDefinitions
5
+
6
+ def require_plugin_entity_definitions
7
+ return unless capabilities[:entity_definitions]
8
+ logger.info "Requiring '#{self.name}' plugin entity definitions..."
9
+ plugin_definition[:entity_definitions].each do |entity_definition_file_path|
10
+ securely_require entity_definition_file_path, fail_on_error: true
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -3,28 +3,11 @@ module PowerStencil
3
3
 
4
4
  module Require
5
5
 
6
- PLUGINS_NAMESPACE = PowerStencil::Plugin
7
- SETUP_PROCESSOR_CALLBACK = :setup_processors
8
- SETUP_DSL_CALLBACK = :setup_dsl
9
- SETUP_ENTITY_DEFINITIONS_CALLBACK = :setup_entity_definitions
10
6
  POST_BUILD_HOOK = :post_build_hook
11
7
 
12
8
  include PowerStencil::Utils::SecureRequire
13
9
  include PowerStencil::Utils::GemUtils
14
10
 
15
- def plugin_module
16
- if PLUGINS_NAMESPACE.constants.include? module_short_name
17
- PLUGINS_NAMESPACE.const_get module_short_name
18
- else
19
- module_name = if respond_to? :name
20
- name.nil? ? 'Unknown' : module_short_name
21
- else
22
- __DIR__
23
- end
24
- raise PowerStencil::Error, "Invalid plugin '#{module_name}'"
25
- end
26
- end
27
-
28
11
  private
29
12
 
30
13
  def module_short_name
@@ -41,9 +24,7 @@ module PowerStencil
41
24
  plugin_root_path = File.dirname(entry_point_path)
42
25
  begin
43
26
  $LOAD_PATH << plugin_root_path
44
- securely_require entry_point_path do
45
- check_plugin_module_capabilities
46
- end
27
+ securely_require entry_point_path unless plugin_definition[:plugin_module].nil?
47
28
  rescue LoadError => e
48
29
  logger.warn "As plugin '#{name}' code is invalid, removing '#{plugin_root_path}' from LOAD_PATH"
49
30
  $LOAD_PATH.delete plugin_root_path
@@ -52,17 +33,6 @@ module PowerStencil
52
33
  end
53
34
  end
54
35
 
55
- def check_plugin_module_capabilities
56
- unless plugin_module.nil?
57
- capabilities[:code] = true
58
- setup_version
59
- end
60
- capabilities[:processors] = plugin_module.respond_to? SETUP_PROCESSOR_CALLBACK
61
- capabilities[:dsl] = plugin_module.respond_to? SETUP_DSL_CALLBACK
62
- capabilities[:entity_definitions] = plugin_module.respond_to? SETUP_ENTITY_DEFINITIONS_CALLBACK
63
- capabilities[:build] = plugin_module.respond_to? POST_BUILD_HOOK
64
- end
65
-
66
36
  def setup_version
67
37
  @version = PowerStencil::Utils::SemanticVersion.new plugin_module::VERSION
68
38
  capabilities[:version] = true
@@ -3,15 +3,17 @@ module PowerStencil
3
3
 
4
4
  module Templates
5
5
 
6
- SETUP_PLUGIN_TEMPLATES = :setup_plugin_templates
7
-
8
6
  def register_plugin_templates
9
- if plugin_module.respond_to? SETUP_PLUGIN_TEMPLATES
10
- logger.debug "Plugin '#{name}' declares to have template(s)."
11
- capabilities[:templates] = true
12
- plugin_module.send SETUP_PLUGIN_TEMPLATES
13
- else
14
- logger.debug "Plugin '#{name}' declares to have no template."
7
+ return unless capabilities[:templates]
8
+ logger.info "Loading '#{self.name}' plugin templates..."
9
+ plugin_definition[:templates].each do |templates_path|
10
+ plugin_templates_path = File.join self.path, templates_path
11
+ Dir.entries(plugin_templates_path).reject { |e| %w(. ..).include? e }.each do |entry|
12
+ template_path = File.join(plugin_templates_path, entry)
13
+ if Dir.exist? template_path
14
+ project.register_template_path_for_type entry.to_sym, template_path
15
+ end
16
+ end
15
17
  end
16
18
  end
17
19
 
@@ -0,0 +1,13 @@
1
+ module PowerStencil
2
+ module Plugins
3
+
4
+ module Type
5
+
6
+ PLUGIN_TYPES = %i(local gem)
7
+
8
+ attr_reader :type
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -29,7 +29,7 @@ module PowerStencil
29
29
  plugin_priority_count + 1
30
30
  end
31
31
  raise PowerStencil::Error, 'Too many plugins !!' if priority >= PROJECT_CONFIG_PRIORITY
32
- add_optional_config_layer yaml_file, "'#{plugin_name}' plugin specific config", priority
32
+ raise PowerStencil::Error, "Invalid config for plugin '#{plugin_name}'" unless add_optional_config_layer yaml_file, "'#{plugin_name}' plugin specific config", priority
33
33
  @plugin_priority_count ||= 0
34
34
  @plugin_priority_count += 1
35
35
  end
@@ -46,8 +46,8 @@ module PowerStencil
46
46
  config << new_config_layer
47
47
  new_config_layer
48
48
  rescue => e
49
- logger.error "The #{layer_name} '#{yaml_file}' is invalid and has been ignored !"
50
49
  logger.debug PowerStencil::Error.report_error(e)
50
+ logger.error "The #{layer_name} '#{yaml_file}' is invalid and has been ignored !"
51
51
  false
52
52
  end
53
53
  else
@@ -51,6 +51,9 @@ module PowerStencil
51
51
  File.join project_plugins_path, plugin_name
52
52
  end
53
53
 
54
+ def plugin_capabilities_definition_file(plugin_name)
55
+ File.join project_plugin_path(plugin_name), 'etc', 'plugin_capabilities.yaml'
56
+ end
54
57
 
55
58
  def plugin_commands_line_definition_file(plugin_name)
56
59
  File.join project_plugin_path(plugin_name), 'etc', 'command_line.yaml'
@@ -23,25 +23,14 @@ module PowerStencil
23
23
  def bootstrap_plugins
24
24
  initialize_gem_plugins
25
25
  initialize_local_plugins
26
- check_plugins_dependencies
27
26
  command_line_manager.definition_hash_to_commands
28
- plugins.each do |plugin_name, plugin|
27
+ plugins.each do |_, plugin|
29
28
  if plugin.capabilities[:processors]
30
- plugin.plugin_module.send PowerStencil::Plugins::Require::SETUP_PROCESSOR_CALLBACK
29
+ plugin.register_processors
31
30
  end
32
31
  end
33
32
  end
34
33
 
35
- def check_plugins_dependencies
36
- plugins.each do |plugin_name, plugin|
37
- begin
38
- plugin.check_plugin_dependencies
39
- rescue PowerStencil::Error => pse
40
- PowerStencil.logger.debug pse.message
41
- PowerStencil.logger.warn "Discarding invalid plugin '#{plugin_name}'."
42
- end
43
- end
44
- end
45
34
 
46
35
  def initialize_gem_plugins
47
36
  # PowerStencil::logger.warn 'Gem plugins not yet supported ! Skipping...'
@@ -78,7 +67,7 @@ module PowerStencil
78
67
  plugins[candidate] = PowerStencil::Plugins::Base.new(candidate, self)
79
68
  rescue PowerStencil::Error => pse
80
69
  PowerStencil.logger.debug pse.message
81
- PowerStencil.logger.warn "Discarding invalid plugin '#{candidate}'."
70
+ PowerStencil.logger.error "Discarding invalid plugin '#{candidate}'."
82
71
  end
83
72
  end
84
73
  end
@@ -7,7 +7,7 @@ module PowerStencil
7
7
  PowerStencil.logger.debug "Securely requiring Ruby source file '#{ruby_source_file}'..."
8
8
  require ruby_source_file
9
9
  yield if block_given?
10
- rescue => e
10
+ rescue StandardError, SyntaxError => e
11
11
  PowerStencil.logger.debug PowerStencil::Error.report_error(e)
12
12
  msg = "Could not require Ruby source file '#{ruby_source_file}' !"
13
13
  if fail_on_error
@@ -1,3 +1,3 @@
1
1
  module PowerStencil
2
- VERSION = '0.4.22'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_stencil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.22
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Briais
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-21 00:00:00.000000000 Z
11
+ date: 2019-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,9 +140,14 @@ files:
140
140
  - doc/templates.md
141
141
  - etc/base_commands_definition.yml
142
142
  - etc/meta_templates/plugin_seed/etc/command_line.yaml
143
+ - etc/meta_templates/plugin_seed/etc/plugin_capabilities.yaml
143
144
  - etc/meta_templates/plugin_seed/etc/plugin_config.yaml
144
145
  - etc/meta_templates/plugin_seed/etc/templates/.git_keep
146
+ - etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/.copy_ignore
147
+ - etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/.subst_ignore
148
+ - etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/message.txt
145
149
  - etc/meta_templates/plugin_seed/lib/{entity}.rb.erb
150
+ - etc/meta_templates/plugin_seed/lib/{entity}/dsl/{entity}_dsl.rb.erb
146
151
  - etc/meta_templates/plugin_seed/lib/{entity}/entity_definitions/{entity}_entity.rb.erb
147
152
  - etc/meta_templates/plugin_seed/lib/{entity}/plugin_helper.rb.erb
148
153
  - etc/meta_templates/plugin_seed/lib/{entity}/version.rb.erb
@@ -160,9 +165,14 @@ files:
160
165
  - etc/templates/plugin_definition/bin/console
161
166
  - etc/templates/plugin_definition/bin/setup
162
167
  - etc/templates/plugin_definition/etc/command_line.yaml
168
+ - etc/templates/plugin_definition/etc/plugin_capabilities.yaml
163
169
  - etc/templates/plugin_definition/etc/plugin_config.yaml
164
170
  - etc/templates/plugin_definition/etc/templates/.git_keep
171
+ - etc/templates/plugin_definition/etc/templates/{entity}_entity/.copy_ignore
172
+ - etc/templates/plugin_definition/etc/templates/{entity}_entity/.subst_ignore
173
+ - etc/templates/plugin_definition/etc/templates/{entity}_entity/message.txt
165
174
  - etc/templates/plugin_definition/lib/{entity}.rb.erb
175
+ - etc/templates/plugin_definition/lib/{entity}/dsl/{entity}_dsl.rb.erb
166
176
  - etc/templates/plugin_definition/lib/{entity}/entity_definitions/{entity}_entity.rb.erb
167
177
  - etc/templates/plugin_definition/lib/{entity}/plugin_helper.rb.erb
168
178
  - etc/templates/plugin_definition/lib/{entity}/version.rb.erb
@@ -216,13 +226,16 @@ files:
216
226
  - lib/power_stencil/error.rb
217
227
  - lib/power_stencil/initializer.rb
218
228
  - lib/power_stencil/plugins/base.rb
229
+ - lib/power_stencil/plugins/build.rb
219
230
  - lib/power_stencil/plugins/capabilities.rb
220
231
  - lib/power_stencil/plugins/command_line.rb
221
232
  - lib/power_stencil/plugins/config.rb
222
- - lib/power_stencil/plugins/dependencies.rb
233
+ - lib/power_stencil/plugins/dsl.rb
234
+ - lib/power_stencil/plugins/entity_definitions.rb
223
235
  - lib/power_stencil/plugins/gem.rb
224
236
  - lib/power_stencil/plugins/require.rb
225
237
  - lib/power_stencil/plugins/templates.rb
238
+ - lib/power_stencil/plugins/type.rb
226
239
  - lib/power_stencil/project/base.rb
227
240
  - lib/power_stencil/project/config.rb
228
241
  - lib/power_stencil/project/create.rb
@@ -261,12 +274,11 @@ metadata:
261
274
  documentation_uri: https://gitlab.com/tools4devops/power_stencil/blob/master/README.md
262
275
  source_code_uri: https://gitlab.com/tools4devops/power_stencil
263
276
  homepage_uri: https://powerstencil.brizone.org/
264
- post_install_message: "\nThank you for installing PowerStencil 0.4.22 !\nFrom the
265
- command line you can run `power_stencil --help`\nIf your shell is not completing
266
- the command:\n If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial
267
- Website : https://powerstencil.brizone.org/\nFull documentation here :
268
- https://gitlab.com/tools4devops/power_stencil/blob/master/README.md\nFeel free to
269
- report issues: https://gitlab.com/tools4devops/power_stencil/issues\n "
277
+ post_install_message: "\nThank you for installing PowerStencil 0.5.0 !\nFrom the command
278
+ line you can run `power_stencil --help`\nIf your shell is not completing the command:\n
279
+ \ If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial Website
280
+ \ : https://powerstencil.brizone.org/\nFull documentation here : https://gitlab.com/tools4devops/power_stencil/blob/master/README.md\nFeel
281
+ free to report issues: https://gitlab.com/tools4devops/power_stencil/issues\n "
270
282
  rdoc_options: []
271
283
  require_paths:
272
284
  - lib
@@ -1,32 +0,0 @@
1
- module PowerStencil
2
- module Plugins
3
-
4
- module Dependencies
5
-
6
- def has_dependencies?
7
- not declared_dependencies.empty?
8
- end
9
-
10
- def declared_dependencies
11
- if plugin_module.constants.include? :REQUIRED_PLUGINS
12
- plugin_module::REQUIRED_PLUGINS
13
- else
14
- []
15
- end
16
- end
17
-
18
- def check_plugin_dependencies
19
- logger.info "Checking plugin '#{name}' dependencies !"
20
- declared_dependencies.each do |dependency|
21
- logger.debug "Checking dependency of plugin '#{name}' to plugin '#{dependency}'"
22
- unless project.plugins.keys.include? dependency.to_s
23
- raise PowerStencil::Error, "Unmatched dependency '#{dependency}' for plugin '#{name}' !"
24
- end
25
- end
26
- logger.debug "Dependencies for plugin '#{name}' are Ok."
27
- end
28
-
29
- end
30
-
31
- end
32
- end