Commit 766d4be2 authored by Laurent Briais's avatar Laurent Briais

Origin identification

parent 0d7cf917
......@@ -20,6 +20,15 @@ Builds
You build a [buildable] entity by issuing `power_stencil build <entity_type>/<entity_name>`. If you try to build an entity which is not buildable, the process fail with an error message.
**:information_source: You can get the list of buildable entities in your repository by issuing a `power_stencil build --list`:**
```
$ power_stencil build --list
- 'simple_exec' (buildable by 'PowerStencil core' and provided by 'PowerStencil core').
```
We will see later in the [templates] part what to do with this `simple_exec` entity type.
Let's describe a bit more in detail what this build process is:
![entity-build-flow]
......@@ -32,7 +41,7 @@ I guess you understood this is not a "real" _compilation_ process we are discuss
The mechanism of the compilation is coming from the [universe_compiler] Gem, but the two following features are the ones you really need to understand.
:information_source: The compilation process can be applied to any entity, ie it doesn't need to be [buildable] (see in next paragraph how to run the compilation). But an entity needs to be [buildable] to use `power_stencil build` which corresponds actually to _compilation_ + _detemplatization_.
:information_source: The compilation process is actually applied to all entities, ie it doesn't need to be [buildable] (see in next paragraph how to run the compilation). But an entity needs to be [buildable] to use `power_stencil build` which corresponds actually to _compilation_ + _detemplatization_.
## Extending an entity
......
......@@ -58,8 +58,8 @@ $ power_stencil info
PROJECT REPORT
--------------------------------------------------------------------------------
General information:
- Project required version: 0.2.18
- PowerStencil version: 0.2.18
- Project required version: 0.6.1
- PowerStencil version: 0.6.1
--------------------------------------------------------------------------------
Paths:
- Project root path: '/tmp/tst2'
......@@ -75,12 +75,12 @@ PROJECT REPORT
- project_config: 1
--------------------------------------------------------------------------------
Available entity types:
- Type 'base_entity' --> PowerStencil::SystemEntityDefinitions::ProjectEntity
- Type 'entity_override' --> UniverseCompiler::Entity::Override
- Type 'plugin_definition' --> PowerStencil::SystemEntityDefinitions::Plugin (template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.2.18/etc/templates/plugin_definition')
- Type 'process_descriptor' --> PowerStencil::SystemEntityDefinitions::ProcessDescriptor
- Type 'project_config' --> PowerStencil::SystemEntityDefinitions::ProjectConfig
- Type 'simple_exec' --> PowerStencil::SystemEntityDefinitions::SimpleExec (template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.2.18/etc/templates/simple_exec')
- Type 'base_entity' --> PowerStencil::SystemEntityDefinitions::ProjectEntity (provided by 'PowerStencil core')
- Type 'entity_override' --> UniverseCompiler::Entity::Override (provided by 'PowerStencil core')
- Type 'plugin_definition' --> PowerStencil::SystemEntityDefinitions::Plugin (provided by 'PowerStencil core') template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.6.1/etc/templates/plugin_definition'
- Type 'process_descriptor' --> PowerStencil::SystemEntityDefinitions::ProcessDescriptor (provided by 'PowerStencil core')
- Type 'project_config' --> PowerStencil::SystemEntityDefinitions::ProjectConfig (provided by 'PowerStencil core')
- Type 'simple_exec' --> PowerStencil::SystemEntityDefinitions::SimpleExec (provided by 'PowerStencil core') template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.6.1/etc/templates/simple_exec'
```
It provides a lot of information about the project, but let's focus on the `Entities` and `Available entity types` parts of the report.
......@@ -178,20 +178,23 @@ We have seen the `power_stencil info` returns (among other) the number of entiti
$ power_stencil check
RAW ENTITIES
'base_entity/my_1st_entity':
- Storage path: '/tmp/tst2/.ps_project/entities/base_entity/my_1st_entity.yaml'
- Status : Valid
- Buildable : false
- Storage path : '/tmp/tst2/.ps_project/entities/base_entity/my_1st_entity.yaml'
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
'base_entity/my_2nd_entity':
- Storage path: '/tmp/tst2/.ps_project/entities/base_entity/my_2nd_entity.yaml'
- Status : Valid
- Buildable : false
- Storage path : '/tmp/tst2/.ps_project/entities/base_entity/my_2nd_entity.yaml'
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
'project_config/Project Config':
- Storage path: ''
- Status : Valid
- Buildable : false
- Storage path : ''
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
```
The goal of this command is normally to check the validity of entities, but it brings as well extra information like if the entity is _buildable_ or even where it is stored in the repository.
The goal of this command is normally to check the validity of entities, but it brings as well extra information like if the entity is _buildable_ or even where it is stored in the repository or if is provided by the core system (PowerStencil core) or a plugin.
:information_source: You can notice that the `project_config` entity has no storage path, the reason being [it is not persisted](#default-entity-types) in the entities repository (its content actually comes from config files outside of the repository).
......@@ -203,13 +206,15 @@ By default `power_stencil check` will check all entities in the repository but y
$ power_stencil check base_entity/my_1st_entity 'project_config/Project Config'
RAW ENTITIES
'base_entity/my_1st_entity':
- Storage path: '/tmp/tst2/.ps_project/entities/base_entity/my_1st_entity.yaml'
- Status : Valid
- Buildable : false
- Storage path : '/tmp/tst2/.ps_project/entities/base_entity/my_1st_entity.yaml'
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
'project_config/Project Config':
- Storage path: ''
- Status : Valid
- Buildable : false
- Storage path : ''
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
```
Another possibility is to check a list of objects using a regular expression (applied to the ID of an entity, ie `<entity_type</<entity_name>`) by using the `--regexp` option:
......@@ -217,13 +222,15 @@ Another possibility is to check a list of objects using a regular expression (ap
$ power_stencil check base_ --regexp
RAW ENTITIES
'base_entity/my_1st_entity':
- Storage path: '/tmp/tst2/.ps_project/entities/base_entity/my_1st_entity.yaml'
- Status : Valid
- Buildable : false
- Storage path : '/tmp/tst2/.ps_project/entities/base_entity/my_1st_entity.yaml'
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
'base_entity/my_2nd_entity':
- Storage path: '/tmp/tst2/.ps_project/entities/base_entity/my_2nd_entity.yaml'
- Status : Valid
- Buildable : false
- Storage path : '/tmp/tst2/.ps_project/entities/base_entity/my_2nd_entity.yaml'
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
```
## Querying and graphing entities
......@@ -336,9 +343,10 @@ Created 'base_entity/dev_entity'
$ power_stencil check base_entity/dev_entity
RAW ENTITIES
'base_entity/dev_entity':
- Storage path: '/tmp/tst2/.ps_project/user_entities/base_entity/dev_entity.yaml'
- Status : Valid
- Buildable : false
- Storage path : '/tmp/tst2/.ps_project/user_entities/base_entity/dev_entity.yaml'
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
```
You can notice where the YAML file has been created.
......@@ -487,13 +495,13 @@ $ power_stencil info
.
--------------------------------------------------------------------------------
Available entity types:
- Type 'base_entity' --> PowerStencil::SystemEntityDefinitions::ProjectEntity
- Type 'base_entity' --> PowerStencil::SystemEntityDefinitions::ProjectEntity (provided by 'PowerStencil core')
- Type 'custom_entity' --> MyCustomEntity
- Type 'entity_override' --> UniverseCompiler::Entity::Override
- Type 'plugin_definition' --> PowerStencil::SystemEntityDefinitions::Plugin (template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.2.18/etc/templates/plugin_definition')
- Type 'process_descriptor' --> PowerStencil::SystemEntityDefinitions::ProcessDescriptor
- Type 'project_config' --> PowerStencil::SystemEntityDefinitions::ProjectConfig
- Type 'simple_exec' --> PowerStencil::SystemEntityDefinitions::SimpleExec (template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.2.18/etc/templates/simple_exec')
- Type 'entity_override' --> UniverseCompiler::Entity::Override (provided by 'PowerStencil core')
- Type 'plugin_definition' --> PowerStencil::SystemEntityDefinitions::Plugin (provided by 'PowerStencil core') template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.6.1/etc/templates/plugin_definition'
- Type 'process_descriptor' --> PowerStencil::SystemEntityDefinitions::ProcessDescriptor (provided by 'PowerStencil core')
- Type 'project_config' --> PowerStencil::SystemEntityDefinitions::ProjectConfig (provided by 'PowerStencil core')
- Type 'simple_exec' --> PowerStencil::SystemEntityDefinitions::SimpleExec (provided by 'PowerStencil core') template-template path: '/opt/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/power_stencil-0.6.1/etc/templates/simple_exec'
```
You see that the `custom_entity` type appeared in the list. Need another proof ?
```shell
......@@ -503,9 +511,10 @@ Created 'custom_entity/my_1st_custom_entity'
$ power_stencil check cust -r
RAW ENTITIES
'custom_entity/my_1st_custom_entity':
- Storage path: '/tmp/tst2/.ps_project/entities/custom_entity/my_1st_custom_entity.yaml'
- Status : Valid
- Buildable : false
- Storage path : '/tmp/tst2/.ps_project/entities/custom_entity/my_1st_custom_entity.yaml'
- Provided by : 'PowerStencil core'
- Status : Valid
- Buildable : false
$ power_stencil get custom_entity/my_1st_custom_entity --raw
--- !ruby/object:MyCustomEntity
......
......@@ -206,6 +206,7 @@ we can check using `power_stencil check myplugin_entity/test`:
$ power_stencil check myplugin_entity/test
'myplugin_entity/test':
- Storage path : '/tmp/demo/.ps_project/entities/myplugin_entity/test.yaml'
- Provided by : plugin 'myplugin'
- Templates path : '/tmp/demo/myplugin_entity/test'
- Status : Valid
- Buildable : true
......
......@@ -43,6 +43,7 @@ $ power_stencil check simple_exec/demo_templates
RAW ENTITIES
'simple_exec/demo_templates':
- Storage path : '/tmp/tst3/.ps_project/entities/simple_exec/demo_templates.yaml'
- Provided by : 'PowerStencil core'
- Templates path : '/tmp/tst3/simple_exec/demo_templates'
- Status : Valid
- Buildable : true
......
......@@ -15,8 +15,21 @@ module PowerStencil
if config[:'supported-builds']
project.engine.available_entities_hash.select do |_, klass|
klass.respond_to?(:buildable?) and klass.buildable?
end .each do |entity_type, _|
puts " - '#{entity_type}'"
end .each do |entity_type, entity_class|
builder = entity_class.buildable_by.empty? ? "'#{PowerStencil.name}'" : "plugin '#{entity_class.buildable_by}'"
source_provider = entity_class.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'"
elsif source_provider == project
"project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'"
else
raise PowerStencil::Error, "Unidentified source provider for #{entity_class} !"
end
puts " - '#{entity_type}' (buildable by #{builder} and provided by #{source_provider_display})."
end
return
end
......
......@@ -23,6 +23,18 @@ module PowerStencil
sorted_targets.map do |entity|
entity_info = [" '#{entity.as_path}':"]
entity_info << " - Storage path : '#{entity.source_uri}'"
source_provider = entity.class.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'"
elsif source_provider == project
"project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'"
else
raise PowerStencil::Error, "Unidentified source provider for #{entity.class} !"
end
entity_info << " - Provided by : #{source_provider_display}"
entity_info << " - Templates path : '#{entity.templates_path}'" if entity.respond_to? :templates_path
entity_info << " - Status : #{entity.valid? ? 'Valid' : 'INVALID !'} "
entity_info << " - Buildable : #{entity.buildable?}"
......
......@@ -25,10 +25,10 @@ module PowerStencil
else
puts "#{project.plugins.size} plugin#{project.plugins.size == 1 ? '' : 's'} found to be used in this project."
end
project.plugins.each do |plugin_name, plugin_def|
puts " - #{plugin_name} (in '#{plugin_def.entry_point_path}')"
project.plugins.each do |_, plugin|
puts " - #{plugin.name} (in '#{plugin.plugin_path}')"
if config[:verbose]
plugin_def.capabilities.each do |name, value|
plugin.capabilities.each do |name, value|
puts " #{name}: #{value}"
end
end
......
......@@ -7,7 +7,7 @@ module PowerStencil
include PowerStencil::Utils::SecureRequire
def require_definition_files(files_or_dirs)
def require_definition_files(files_or_dirs, source)
required_files = []
files_or_dirs.each do |file_or_dir|
if File.directory? file_or_dir and File.readable? file_or_dir
......@@ -21,21 +21,30 @@ module PowerStencil
next
end
# This is a ruby library or there is something wrong
securely_require file_or_dir
# unless securely_require file_or_dir
# logger.warn "While trying to load definition files, found that '#{file_or_dir}' has a problem. Ignored..."
# end
securely_require_with_entity_class_detection file_or_dir, source
end
required_files.sort!.each {|file| securely_require file, fail_on_error: true}
required_files.sort!.each { |file| securely_require_with_entity_class_detection file, source }
required_files
end
private
def load_system_entities_definition
require_definition_files [SYSTEM_ENTITY_DEFINITION_ENTRY_POINT]
require_definition_files [SYSTEM_ENTITY_DEFINITION_ENTRY_POINT], PowerStencil
end
def securely_require_with_entity_class_detection(entity_definition_file_path, source)
before = PowerStencil::Engine::EntitiesHandling.all_types
securely_require entity_definition_file_path, fail_on_error: true
after = PowerStencil::Engine::EntitiesHandling.all_types
after.reject { |k, _| before.keys.include? k }
.each do |_, plugin_entity_class|
plugin_entity_class.instance_eval do
@entity_type_source_provider = source
end
end
end
end
end
......
......@@ -36,7 +36,7 @@ module PowerStencil
if Dir.exist? dir and File.readable? dir
logger.info 'Loading project specific entity definitions.'
$LOAD_PATH << dir
require_definition_files [dir]
require_definition_files [dir], project
end
end
......
......@@ -8,6 +8,10 @@ module PowerStencil
include Climatic::Proxy
def name
'PowerStencil core'
end
def bootstrap(cmd_line_args = ARGV.dup)
setup_climatic cmd_line_args
logger.debug 'Starting PowerStencil initialization...'
......
......@@ -6,9 +6,24 @@ module PowerStencil
def require_plugin_entity_definitions
return unless capabilities[:entity_definitions]
logger.info "Requiring '#{self.name}' plugin entity definitions..."
securely_require_with_entity_class_detection
end
private
def securely_require_with_entity_class_detection
before = PowerStencil::Engine::EntitiesHandling.all_types
plugin_definition[:entity_definitions].each do |entity_definition_file_path|
securely_require entity_definition_file_path, fail_on_error: true
end
after = PowerStencil::Engine::EntitiesHandling.all_types
after.reject { |k, _| before.keys.include? k }.each do |_, plugin_entity_class|
plugin = self
plugin_entity_class.instance_eval do
@entity_type_source_provider = plugin
end
end
end
end
......
......@@ -21,6 +21,7 @@ module PowerStencil
$LOAD_PATH << plugin_root_path
securely_require entry_point_path unless plugin_definition[:plugin_module].nil?
rescue LoadError => e
@entry_point_path = nil
logger.warn "As plugin '#{name}' code is invalid, removing '#{plugin_root_path}' from LOAD_PATH"
$LOAD_PATH.delete plugin_root_path
end
......
......@@ -34,6 +34,10 @@ module PowerStencil
attr_reader :engine, :entity_engine
def name
File.dirname project_config_root
end
def initialize(search_from_path: Dir.pwd)
initialize_paths search_from_path
load_project_specific_config
......
......@@ -60,7 +60,20 @@ module PowerStencil
.sort{ |a,b| a.first <=> b.first }
.each do |type, klass|
msg = "Type '#{type}' --> #{klass}"
msg << " (template-template path: '#{entity_type_templates[type]}')" unless entity_type_templates[type].nil?
source_provider = klass.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'"
elsif source_provider == self
"project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'"
else
raise PowerStencil::Error, "Unidentified source provider for #{klass} !"
end
msg << " (provided by #{source_provider_display})"
msg << " template-template path: '#{entity_type_templates[type]}'" unless entity_type_templates[type].nil?
report << msg
end
report
......
......@@ -3,6 +3,7 @@
require 'power_stencil/system_entity_definitions/non_persistent'
require 'power_stencil/system_entity_definitions/has_associated_files'
require 'power_stencil/system_entity_definitions/source_provider'
require 'power_stencil/system_entity_definitions/buildable'
require 'power_stencil/system_entity_definitions/entity_project_common'
......
class UniverseCompiler::Entity::Override
extend PowerStencil::SystemEntityDefinitions::SourceProvider
extend PowerStencil::SystemEntityDefinitions::Buildable
include PowerStencil::SystemEntityDefinitions::EntityProjectCommon
......
......@@ -3,7 +3,7 @@ module PowerStencil
module EntityProjectCommon
def save(uri = source_uri, raise_error: true, force_save: false, force_files_generation: false )
def save(uri = source_uri, raise_error: true, force_save: false, force_files_generation: false )
super(source_uri, raise_error: raise_error, force_save: force_save)
unless PowerStencil.project.entity_type_templates[type].nil?
PowerStencil.project.generate_entity_dir_for_entity self, force: force_files_generation
......
......@@ -3,6 +3,7 @@ module PowerStencil
class ProjectEntity < UniverseCompiler::Entity::Base
extend PowerStencil::SystemEntityDefinitions::SourceProvider
extend PowerStencil::SystemEntityDefinitions::Buildable
include PowerStencil::SystemEntityDefinitions::EntityProjectCommon
......
......@@ -9,7 +9,7 @@ module PowerStencil
entity_type :simple_exec
buildable_by ''
buildable
has_one :process_descriptor, name: :post_process
not_null :post_process
......
module PowerStencil
module SystemEntityDefinitions
module SourceProvider
DEFAULT_PROVIDER = PowerStencil
def entity_type_source_provider
@entity_type_source_provider ||= DEFAULT_PROVIDER
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment