power_stencil 0.5.1 → 0.7.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.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +2 -0
- data/README.md +3 -7
- data/doc/builds.md +10 -1
- data/doc/entities.md +59 -50
- data/doc/images/power-stencil-entity-creation.svg +247 -114
- data/doc/plugins.md +49 -1
- data/doc/templates.md +23 -18
- data/etc/base_commands_definition.yml +28 -1
- data/etc/meta_templates/plugin_seed/psplugin_{entity}.gemspec +3 -1
- data/etc/power_stencil.yaml +7 -1
- data/etc/templates/plugin_definition/psplugin_{entity}.gemspec +3 -1
- data/etc/templates/project/.zzzgitignore.erb +8 -3
- data/lib/power_stencil.rb +1 -0
- data/lib/power_stencil/command_processors/build.rb +16 -3
- data/lib/power_stencil/command_processors/check.rb +12 -0
- data/lib/power_stencil/command_processors/create.rb +6 -5
- data/lib/power_stencil/command_processors/delete.rb +23 -15
- data/lib/power_stencil/command_processors/edit.rb +4 -2
- data/lib/power_stencil/command_processors/init.rb +2 -2
- data/lib/power_stencil/command_processors/plugin.rb +20 -6
- data/lib/power_stencil/command_processors/root.rb +1 -1
- data/lib/power_stencil/command_processors/shell.rb +10 -3
- data/lib/power_stencil/dsl/entities.rb +0 -16
- data/lib/power_stencil/engine/build_handling.rb +1 -2
- data/lib/power_stencil/engine/directory_processor.rb +6 -1
- data/lib/power_stencil/engine/entities_definitions.rb +16 -7
- data/lib/power_stencil/engine/entities_handling.rb +1 -1
- data/lib/power_stencil/engine/project_engine.rb +6 -10
- data/lib/power_stencil/initializer.rb +4 -7
- data/lib/power_stencil/plugins/base.rb +18 -9
- data/lib/power_stencil/plugins/capabilities.rb +10 -8
- data/lib/power_stencil/plugins/command_line.rb +1 -4
- data/lib/power_stencil/plugins/config.rb +1 -5
- data/lib/power_stencil/plugins/entity_definitions.rb +15 -0
- data/lib/power_stencil/plugins/gem.rb +14 -35
- data/lib/power_stencil/plugins/paths.rb +38 -0
- data/lib/power_stencil/plugins/require.rb +10 -16
- data/lib/power_stencil/plugins/templates.rb +3 -3
- data/lib/power_stencil/project/base.rb +24 -9
- data/lib/power_stencil/project/config.rb +3 -2
- data/lib/power_stencil/project/create.rb +23 -2
- data/lib/power_stencil/project/git.rb +75 -0
- data/lib/power_stencil/project/info.rb +14 -1
- data/lib/power_stencil/project/paths.rb +22 -26
- data/lib/power_stencil/project/plugins.rb +18 -23
- data/lib/power_stencil/project/templates.rb +15 -22
- data/lib/power_stencil/system_entity_definitions/all.rb +2 -1
- data/lib/power_stencil/system_entity_definitions/buildable.rb +1 -1
- data/lib/power_stencil/system_entity_definitions/entity_override.rb +6 -0
- data/lib/power_stencil/system_entity_definitions/entity_project_common.rb +13 -5
- data/lib/power_stencil/system_entity_definitions/{has_associated_files.rb → entity_templates.rb} +2 -2
- data/lib/power_stencil/system_entity_definitions/project_config.rb +1 -1
- data/lib/power_stencil/system_entity_definitions/project_entity.rb +7 -0
- data/lib/power_stencil/system_entity_definitions/simple_exec.rb +3 -3
- data/lib/power_stencil/system_entity_definitions/source_provider.rb +15 -0
- data/lib/power_stencil/utils/gem_utils.rb +22 -2
- data/lib/power_stencil/version.rb +1 -1
- data/power_stencil.gemspec +2 -1
- metadata +23 -6
@@ -12,8 +12,10 @@ module PowerStencil
|
|
12
12
|
def execute
|
13
13
|
targets = targets_from_criteria analyse_extra_params, project.engine.root_universe
|
14
14
|
targets.each do |target|
|
15
|
-
|
16
|
-
|
15
|
+
project.track_action_with_git("Edited entity '#{target.as_path}'.") do
|
16
|
+
securely_edit_file target.source_uri do |modified_path, _|
|
17
|
+
modifications_valid? modified_path, target
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -15,9 +15,9 @@ module PowerStencil
|
|
15
15
|
def execute
|
16
16
|
setup_project_path
|
17
17
|
log_startup_context
|
18
|
-
puts_and_logs "Creating new project structure in '#{config[:'project-path']}'"
|
18
|
+
puts_and_logs "Creating new project structure in '#{config[:'project-path']}'", check_verbose: false
|
19
19
|
PowerStencil::Project::Base.create_project_tree config[:'project-path']
|
20
|
-
puts_and_logs 'Done.'
|
20
|
+
puts_and_logs 'Done.', check_verbose: false
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
@@ -8,6 +8,16 @@ module PowerStencil
|
|
8
8
|
include PowerStencil::Project::Proxy
|
9
9
|
|
10
10
|
def execute
|
11
|
+
|
12
|
+
if config[:install]
|
13
|
+
config[:project_plugins].each do |plugin_definition|
|
14
|
+
gem_name, gem_req = PowerStencil::Plugins::Base.plugin_definition_to_name_and_req plugin_definition
|
15
|
+
specs = PowerStencil::Plugins::Base.install_gem gem_name, gem_req
|
16
|
+
spec = specs.first
|
17
|
+
puts "Installed plugin '#{spec.name}' (version: #{spec.version})"
|
18
|
+
end
|
19
|
+
return
|
20
|
+
end
|
11
21
|
|
12
22
|
if config[:list]
|
13
23
|
if project.plugins.empty?
|
@@ -15,10 +25,10 @@ module PowerStencil
|
|
15
25
|
else
|
16
26
|
puts "#{project.plugins.size} plugin#{project.plugins.size == 1 ? '' : 's'} found to be used in this project."
|
17
27
|
end
|
18
|
-
project.plugins.each do |
|
19
|
-
puts " - #{
|
28
|
+
project.plugins.each do |_, plugin|
|
29
|
+
puts " - #{plugin.name} (in '#{plugin.plugin_path}')"
|
20
30
|
if config[:verbose]
|
21
|
-
|
31
|
+
plugin.capabilities.each do |name, value|
|
22
32
|
puts " #{name}: #{value}"
|
23
33
|
end
|
24
34
|
end
|
@@ -33,9 +43,13 @@ module PowerStencil
|
|
33
43
|
end
|
34
44
|
config.command_line_layer.extra_parameters.each do |plugin_name|
|
35
45
|
begin
|
36
|
-
target_path = File.join project.
|
37
|
-
|
38
|
-
|
46
|
+
target_path = File.join project.project_local_plugin_path(plugin_name)
|
47
|
+
msg = "Generated new local plugin '#{plugin_name}'."
|
48
|
+
project.track_action_with_git(msg) do
|
49
|
+
project.create_new_local_plugin_tree plugin_name, target_path
|
50
|
+
puts_and_logs msg, check_verbose: false
|
51
|
+
end
|
52
|
+
|
39
53
|
rescue => e
|
40
54
|
msg = "Could not create plugin '#{plugin_name}' because '#{e.message}'"
|
41
55
|
puts msg
|
@@ -18,7 +18,7 @@ module PowerStencil
|
|
18
18
|
unless config.command_line_layer.extra_parameters.empty?
|
19
19
|
raise PowerStencil::Error, "Invalid command '#{config.command_line_layer.extra_parameters.first}'"
|
20
20
|
end
|
21
|
-
puts_and_logs 'No action specified. Exiting...'
|
21
|
+
puts_and_logs 'No action specified. Exiting...', check_verbose: false
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -8,6 +8,7 @@ module PowerStencil
|
|
8
8
|
include Climatic::Proxy
|
9
9
|
include PowerStencil::Project::Proxy
|
10
10
|
|
11
|
+
|
11
12
|
def execute
|
12
13
|
|
13
14
|
working_universe = if config[:compiled]
|
@@ -25,9 +26,15 @@ module PowerStencil
|
|
25
26
|
puts config[:shell_dsl][:session_greetings]
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
msg = 'Changes done in PowerStencil shell session.'
|
30
|
+
project.track_action_with_git(msg,
|
31
|
+
user_validation_required: true,
|
32
|
+
validation_message: 'Would you like to commit your changes ?',
|
33
|
+
show_files_to_commit: true) do
|
34
|
+
Pry.start context,
|
35
|
+
prompt: [proc { config[:shell_dsl][:prompt_level_1] }, proc { config[:shell_dsl][:prompt_level_2] }],
|
36
|
+
quiet: true
|
37
|
+
end
|
31
38
|
|
32
39
|
end
|
33
40
|
|
@@ -31,22 +31,6 @@ module PowerStencil
|
|
31
31
|
PowerStencil.project.engine.entity type, name, @universe
|
32
32
|
end
|
33
33
|
|
34
|
-
# Need to implement a `replace` method which would rename files before...
|
35
|
-
# def edit_entity(type, name)
|
36
|
-
# tmp = Object.new
|
37
|
-
# tmp.extend PowerStencil::Utils::FileEdit
|
38
|
-
# org = entity(type, name)
|
39
|
-
# unless org.nil?
|
40
|
-
# mod = tmp.securely_edit_entity entity(type, name)
|
41
|
-
# raise PowerStencil::Error "You cannot "
|
42
|
-
#
|
43
|
-
#
|
44
|
-
# universe = org.universe
|
45
|
-
# universe.delete org
|
46
|
-
# universe.add mod
|
47
|
-
# end
|
48
|
-
# end
|
49
|
-
|
50
34
|
def entities(criterion: nil, value: nil, &filter_block)
|
51
35
|
PowerStencil.project.engine.entities @universe, criterion: criterion, value: value, &filter_block
|
52
36
|
end
|
@@ -39,8 +39,7 @@ module PowerStencil
|
|
39
39
|
build_entity entity_to_build, build_entity_target_path
|
40
40
|
|
41
41
|
entity_build_report << 'Ok'
|
42
|
-
rescue => e
|
43
|
-
logger.error "Failed building '#{entity_to_build.as_path}' because '#{e.message}' !"
|
42
|
+
rescue SyntaxError, StandardError => e
|
44
43
|
entity_build_report << e.message
|
45
44
|
if fail_on_error
|
46
45
|
raise e
|
@@ -97,7 +97,12 @@ module PowerStencil
|
|
97
97
|
raise PowerStencil::Error, "File '#{source}' is supposed to be rendered using '#{engine_name}', but seems not to be supported !"
|
98
98
|
end
|
99
99
|
context = running_context universe, main_entry_point: main_entry_point
|
100
|
-
|
100
|
+
begin
|
101
|
+
return send templating_engine_method_name, source, context
|
102
|
+
rescue StandardError, SyntaxError => e
|
103
|
+
logger.puts_and_logs "Error rendering #{engine_name} template '#{source}'", logs_as: :error, check_verbose: false
|
104
|
+
raise e
|
105
|
+
end
|
101
106
|
end
|
102
107
|
end
|
103
108
|
logger.warn "File '#{source}' was supposed to be processed but there is no template engine defined ! Applying simple copy."
|
@@ -7,7 +7,7 @@ module PowerStencil
|
|
7
7
|
|
8
8
|
include PowerStencil::Utils::SecureRequire
|
9
9
|
|
10
|
-
def require_definition_files(files_or_dirs)
|
10
|
+
def require_definition_files(files_or_dirs, source)
|
11
11
|
required_files = []
|
12
12
|
files_or_dirs.each do |file_or_dir|
|
13
13
|
if File.directory? file_or_dir and File.readable? file_or_dir
|
@@ -21,21 +21,30 @@ module PowerStencil
|
|
21
21
|
next
|
22
22
|
end
|
23
23
|
# This is a ruby library or there is something wrong
|
24
|
-
|
25
|
-
|
26
|
-
# logger.warn "While trying to load definition files, found that '#{file_or_dir}' has a problem. Ignored..."
|
27
|
-
# end
|
24
|
+
securely_require_with_entity_class_detection file_or_dir, source
|
25
|
+
|
28
26
|
end
|
29
|
-
required_files.sort!.each {|file|
|
27
|
+
required_files.sort!.each { |file| securely_require_with_entity_class_detection file, source }
|
30
28
|
required_files
|
31
29
|
end
|
32
30
|
|
33
31
|
private
|
34
32
|
|
35
33
|
def load_system_entities_definition
|
36
|
-
require_definition_files [SYSTEM_ENTITY_DEFINITION_ENTRY_POINT]
|
34
|
+
require_definition_files [SYSTEM_ENTITY_DEFINITION_ENTRY_POINT], PowerStencil
|
37
35
|
end
|
38
36
|
|
37
|
+
def securely_require_with_entity_class_detection(entity_definition_file_path, source)
|
38
|
+
before = PowerStencil::Engine::EntitiesHandling.all_types
|
39
|
+
securely_require entity_definition_file_path, fail_on_error: true
|
40
|
+
after = PowerStencil::Engine::EntitiesHandling.all_types
|
41
|
+
after.reject { |k, _| before.keys.include? k }
|
42
|
+
.each do |_, plugin_entity_class|
|
43
|
+
plugin_entity_class.instance_eval do
|
44
|
+
@entity_type_source_provider = source
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
39
48
|
end
|
40
49
|
|
41
50
|
end
|
@@ -59,7 +59,7 @@ module PowerStencil
|
|
59
59
|
raise PowerStencil::Error, "Unknown entity type: '#{type}'"
|
60
60
|
end
|
61
61
|
fields[:name] = fields[:name].to_s
|
62
|
-
res = @available_entities_hash[type.to_sym].new fields: fields, universe: work_universe
|
62
|
+
res = @available_entities_hash[type.to_sym].new fields: fields, universe: work_universe, user: user
|
63
63
|
logger.debug "Created new '#{type}': \n#{fields.to_yaml}"
|
64
64
|
work_universe.add res
|
65
65
|
if work_universe == PowerStencil.project.engine.root_universe
|
@@ -36,7 +36,7 @@ module PowerStencil
|
|
36
36
|
if Dir.exist? dir and File.readable? dir
|
37
37
|
logger.info 'Loading project specific entity definitions.'
|
38
38
|
$LOAD_PATH << dir
|
39
|
-
require_definition_files [dir]
|
39
|
+
require_definition_files [dir], project
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -62,24 +62,20 @@ module PowerStencil
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def load_project_entities
|
65
|
-
logger.debug 'Loading project entities - NOT IMPLEMENTED'
|
66
65
|
root_universe.import project.project_entities_path, stop_on_error: false do |new_entity|
|
67
|
-
|
66
|
+
logger.debug "Loaded entity: '#{new_entity.as_path}'"
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
70
|
def load_user_entities
|
72
|
-
logger.debug 'Loading user entities - NOT IMPLEMENTED'
|
73
71
|
root_universe.import project.user_entities_path, stop_on_error: false do |new_entity|
|
74
|
-
|
72
|
+
logger.debug "Loaded unversioned entity: '#{new_entity.as_path}'"
|
73
|
+
new_entity.instance_eval do
|
74
|
+
@is_versioned_entity = false
|
75
|
+
end
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
78
|
-
def process_entity(entity)
|
79
|
-
logger.debug "New entity: '#{entity.name}' (#{entity.type})"
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
79
|
end
|
84
80
|
|
85
81
|
end
|
@@ -8,17 +8,15 @@ module PowerStencil
|
|
8
8
|
|
9
9
|
include Climatic::Proxy
|
10
10
|
|
11
|
+
def name
|
12
|
+
'PowerStencil core'
|
13
|
+
end
|
14
|
+
|
11
15
|
def bootstrap(cmd_line_args = ARGV.dup)
|
12
16
|
setup_climatic cmd_line_args
|
13
17
|
logger.debug 'Starting PowerStencil initialization...'
|
14
18
|
setup_system_processors
|
15
19
|
setup_universe_compiler_logger
|
16
|
-
# @project = try_to_load_project fail_on_error: false
|
17
|
-
begin
|
18
|
-
project.setup_templates_for_entities # unless project.nil?
|
19
|
-
rescue => e
|
20
|
-
logger.debug PowerStencil::Error.report_error e
|
21
|
-
end
|
22
20
|
logger.debug 'PowerStencil initialization complete'
|
23
21
|
end
|
24
22
|
|
@@ -32,7 +30,6 @@ module PowerStencil
|
|
32
30
|
|
33
31
|
def try_to_load_project(fail_on_error: true)
|
34
32
|
PowerStencil::Project::Base.instantiate_from_config config
|
35
|
-
|
36
33
|
end
|
37
34
|
|
38
35
|
def setup_system_processors
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'power_stencil/plugins/paths'
|
1
2
|
require 'power_stencil/plugins/type'
|
2
3
|
require 'power_stencil/plugins/config'
|
3
4
|
require 'power_stencil/plugins/command_line'
|
@@ -19,6 +20,7 @@ module PowerStencil
|
|
19
20
|
|
20
21
|
include Climatic::Proxy
|
21
22
|
include PowerStencil::Plugins::Type
|
23
|
+
include PowerStencil::Plugins::Paths
|
22
24
|
include PowerStencil::Plugins::Config
|
23
25
|
include PowerStencil::Plugins::CommandLine
|
24
26
|
include PowerStencil::Plugins::Require
|
@@ -28,27 +30,34 @@ module PowerStencil
|
|
28
30
|
include PowerStencil::Plugins::Build
|
29
31
|
include PowerStencil::Plugins::Dsl
|
30
32
|
|
31
|
-
attr_reader :name, :version, :entry_point_path
|
33
|
+
attr_reader :name, :version, :entry_point_path, :gem_spec
|
32
34
|
|
33
|
-
def initialize(name, project, type
|
35
|
+
def initialize(name, project, type: :local, gem_req: nil)
|
34
36
|
@name = name
|
35
37
|
@project = project
|
36
38
|
@version = PowerStencil::Utils::SemanticVersion.new '0.0.0-not-specified'
|
37
39
|
raise PowerStencil::Error, "Invalid plugin type (#{type}) for plugin '#{name}'" unless PLUGIN_TYPES.include? type
|
38
40
|
@type = type
|
41
|
+
case type
|
42
|
+
when :gem
|
43
|
+
logger.debug "Plugin '#{name}' is provided as a Gem."
|
44
|
+
@gem_spec = PowerStencil::Plugins::Base.find_locally_installed_gem_spec name, gem_req
|
45
|
+
raise PowerStencil::Error, "Cannot find plugin '#{name}'. Try 'power_stencil plugin --install'" if gem_spec.nil?
|
46
|
+
raise PowerStencil::Error, "Invalid plugin '#{name}' ! Missing metadata 'plugin_name' in spec !" if gem_spec.metadata['plugin_name'].nil?
|
47
|
+
logger.debug "Plugin '#{name}' real name is '#{gem_spec.metadata['plugin_name']}'."
|
48
|
+
@name = gem_spec.metadata['plugin_name']
|
49
|
+
when :local
|
50
|
+
logger.debug "Plugin '#{name}' is provided locally by the project."
|
51
|
+
else
|
52
|
+
raise PowerStencil::Error, "Unsupported plugin type (#{type}) for plugin '#{name}' !"
|
53
|
+
end
|
54
|
+
|
39
55
|
logger.debug "Loading plugin '#{name}'..."
|
40
56
|
setup_plugin
|
41
57
|
logger.info "Plugin '#{name}' successfully available"
|
42
58
|
logger.debug "Plugin '#{name}' has following capabilities: #{capabilities.inspect}"
|
43
59
|
end
|
44
60
|
|
45
|
-
def path
|
46
|
-
case type
|
47
|
-
when :local
|
48
|
-
project.project_plugin_path(name)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
61
|
def plugin_module
|
53
62
|
Object.const_get plugin_definition[:plugin_module]
|
54
63
|
end
|
@@ -9,10 +9,6 @@ module PowerStencil
|
|
9
9
|
|
10
10
|
attr_reader :plugin_definition
|
11
11
|
|
12
|
-
def plugin_capabilities_definition_file
|
13
|
-
project.plugin_capabilities_definition_file self.name
|
14
|
-
end
|
15
|
-
|
16
12
|
def capabilities
|
17
13
|
@capabilities ||= CAPABILITIES.dup.zip([false] * CAPABILITIES.size).to_h
|
18
14
|
end
|
@@ -24,11 +20,17 @@ module PowerStencil
|
|
24
20
|
unless File.exists? yaml_file and File.file? yaml_file and File.readable? yaml_file
|
25
21
|
raise PowerStencil::Error, "Plugin '#{self.name}' has no definition file !"
|
26
22
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
logger.debug "Loading plugin '#{self.name}' capabilities..."
|
24
|
+
begin
|
25
|
+
@plugin_definition = yaml_file_to_hash yaml_file
|
26
|
+
%i(processors entity_definitions templates build dsl).each do |capability|
|
27
|
+
unless plugin_definition[capability].nil? or plugin_definition[capability].empty?
|
28
|
+
capabilities[capability] = true
|
29
|
+
end
|
31
30
|
end
|
31
|
+
rescue => e
|
32
|
+
logger.debug PowerStencil::Error.report_error(e)
|
33
|
+
raise PowerStencil::Error, "Invalid plugin capabilities file '#{yaml_file}' for plugin '#{self.name}'"
|
32
34
|
end
|
33
35
|
|
34
36
|
end
|
@@ -5,9 +5,6 @@ module PowerStencil
|
|
5
5
|
|
6
6
|
attr_reader :plugin_command_line_modifier
|
7
7
|
|
8
|
-
def plugin_commands_line_definition_file
|
9
|
-
project.plugin_commands_line_definition_file self.name
|
10
|
-
end
|
11
8
|
|
12
9
|
def register_processors
|
13
10
|
plugin_definition[:processors].each do |processors_name, processor|
|
@@ -20,7 +17,7 @@ module PowerStencil
|
|
20
17
|
private
|
21
18
|
|
22
19
|
def load_yaml_command_definition
|
23
|
-
yaml_file =
|
20
|
+
yaml_file = plugin_command_line_definition_file
|
24
21
|
if File.exists? yaml_file and File.file? yaml_file and File.readable? yaml_file
|
25
22
|
logger.info "Adding extra command line definition for '#{name}' plugin..."
|
26
23
|
@plugin_command_line_modifier = project.yaml_file_to_hash yaml_file
|
@@ -3,17 +3,13 @@ module PowerStencil
|
|
3
3
|
|
4
4
|
module Config
|
5
5
|
|
6
|
-
def plugin_config_specific_file
|
7
|
-
project.plugin_config_specific_file self.name
|
8
|
-
end
|
9
|
-
|
10
6
|
private
|
11
7
|
|
12
8
|
def load_plugin_specific_config
|
13
9
|
yaml_file = plugin_config_specific_file
|
14
10
|
if File.exists? yaml_file and File.file? yaml_file and File.readable? yaml_file
|
15
11
|
logger.info "Found plugin specific config in plugin '#{self.name}'. Attempting to load..."
|
16
|
-
project.add_plugin_config self
|
12
|
+
project.add_plugin_config self
|
17
13
|
capabilities[:config] = true
|
18
14
|
end
|
19
15
|
rescue => e
|
@@ -6,9 +6,24 @@ module PowerStencil
|
|
6
6
|
def require_plugin_entity_definitions
|
7
7
|
return unless capabilities[:entity_definitions]
|
8
8
|
logger.info "Requiring '#{self.name}' plugin entity definitions..."
|
9
|
+
securely_require_with_entity_class_detection
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def securely_require_with_entity_class_detection
|
16
|
+
before = PowerStencil::Engine::EntitiesHandling.all_types
|
9
17
|
plugin_definition[:entity_definitions].each do |entity_definition_file_path|
|
10
18
|
securely_require entity_definition_file_path, fail_on_error: true
|
11
19
|
end
|
20
|
+
after = PowerStencil::Engine::EntitiesHandling.all_types
|
21
|
+
after.reject { |k, _| before.keys.include? k }.each do |_, plugin_entity_class|
|
22
|
+
plugin = self
|
23
|
+
plugin_entity_class.instance_eval do
|
24
|
+
@entity_type_source_provider = plugin
|
25
|
+
end
|
26
|
+
end
|
12
27
|
end
|
13
28
|
|
14
29
|
end
|
@@ -5,50 +5,29 @@ module PowerStencil
|
|
5
5
|
|
6
6
|
module Gem
|
7
7
|
|
8
|
+
include PowerStencil::Utils::GemUtils
|
9
|
+
|
8
10
|
NO_DOC = %w(--no-document).freeze
|
9
11
|
|
10
|
-
def gem_locally_installed?(plugin_name, plugin_requirements)
|
11
|
-
get_spec(plugin_name, plugin_requirements).nil? ? false : true
|
12
|
-
end
|
13
12
|
|
13
|
+
def is_available_gem?(gem_name)
|
14
14
|
|
15
|
-
def install_gem(plugin_name, plugin_requirements)
|
16
|
-
cmd = ::Gem::Commands::InstallCommand.new
|
17
|
-
opts = [plugin_name]
|
18
|
-
opts << plugin_requirements unless plugin_requirements.empty?
|
19
|
-
opts.concat NO_DOC
|
20
|
-
cmd.handle_options opts
|
21
|
-
PowerStencil.logger.debug "Installing plugin '#{plugin_name}'..."
|
22
|
-
cmd.execute
|
23
|
-
PowerStencil.logger.debug "Plugin '#{plugin_name}' successfully installed."
|
24
|
-
rescue ::Gem::SystemExitException => e
|
25
|
-
PowerStencil.logger.warn PowerStencil::Error.report_error(e)
|
26
15
|
end
|
27
16
|
|
17
|
+
def install_gem(plugin_name, plugin_requirements)
|
18
|
+
::Gem.install plugin_name, plugin_requirements
|
19
|
+
end
|
28
20
|
|
29
21
|
|
30
|
-
private
|
31
|
-
|
32
|
-
def get_spec(plugin_name, plugin_requirements)
|
33
|
-
candidates = ::Gem::Specification.find_all_by_name plugin_name
|
34
|
-
if candidates.empty?
|
35
|
-
PowerStencil.logger.debug "Could not find required plugin '#{plugin_name}'"
|
36
|
-
return nil
|
37
|
-
end
|
38
|
-
|
39
|
-
req = if plugin_requirements.nil? or plugin_requirements.empty?
|
40
|
-
::Gem::Requirement::DefaultRequirement
|
41
|
-
else
|
42
|
-
::Gem::Requirement.create plugin_requirements
|
43
|
-
end
|
44
|
-
|
45
|
-
selected = candidates.select {|candidate| req.satisfied_by? candidate.version}.sort {|a, b| a.version <=> b.version}
|
46
|
-
if candidates.empty?
|
47
|
-
PowerStencil.logger.debug "Could not find required plugin '#{plugin_name}'"
|
48
|
-
return nil
|
49
|
-
end
|
50
|
-
selected.last
|
51
22
|
|
23
|
+
def find_locally_installed_gem_spec(gem_name, gem_requirements = ::Gem::Requirement.default)
|
24
|
+
# Normal method to find gem_spec doesn't work in the context of bundler !!
|
25
|
+
# candidates = ::Gem::Specification.find_all_by_name gem_name
|
26
|
+
candidates = find_gemspec_manually(gem_name)
|
27
|
+
.select {|candidate| gem_requirements.satisfied_by? candidate.version}
|
28
|
+
.sort {|a, b| a.version <=> b.version}
|
29
|
+
PowerStencil.logger.error "Could not find required plugin '#{gem_name}'" if candidates.empty?
|
30
|
+
candidates.last
|
52
31
|
end
|
53
32
|
|
54
33
|
end
|