diff --git a/lib/teracy-dev.rb b/lib/teracy-dev.rb index 0fc73c9d..bf6a7256 100644 --- a/lib/teracy-dev.rb +++ b/lib/teracy-dev.rb @@ -3,6 +3,7 @@ require_relative 'teracy-dev/logging' require_relative 'teracy-dev/loader' +require_relative 'teracy-dev/extension/manager' # define public APIs here @@ -24,6 +25,19 @@ def self.register_configurator(configurator) @@loader.configManager.register(configurator) end + # find the extension lookup_path by its name + def self.extension_lookup_path(extension_name) + extensions = @@loader.settings['teracy-dev']['extensions'] ||= [] + extensions.each do |ext| + manifest = Extension::Manager.manifest(ext) + if manifest['name'] == extension_name + return ext['path']['lookup'] + end + end + # extension_name not found + return nil + end + @@loader.start end diff --git a/lib/teracy-dev/extension/manager.rb b/lib/teracy-dev/extension/manager.rb index f894c4af..87e730e6 100644 --- a/lib/teracy-dev/extension/manager.rb +++ b/lib/teracy-dev/extension/manager.rb @@ -1,6 +1,14 @@ module TeracyDev module Extension class Manager + + def self.manifest(extension) + lookup_path = File.join(TeracyDev::BASE_DIR, extension['path']['lookup'] || 'extensions') + path = File.join(lookup_path, extension['path']['extension']) + manifest_path = File.join(path, 'manifest.yaml') + return YAML.load(File.new(manifest_path)) + end + def initialize @logger = Logging.logger_for(self.class.name) end @@ -50,31 +58,23 @@ def sync(extension) def validate(extension) return if extension['enabled'] != true - lookup_path = File.join(TeracyDev::BASE_DIR, extension['path']['lookup'] || 'extensions') - path = File.join(lookup_path, extension['path']['extension']) - manifest_path = File.join(path, 'manifest.yaml') + manifest = Manager.manifest(extension) - if File.exist? manifest_path - manifest = Util.load_yaml_file(manifest_path) - if !Util.exist?(manifest['name']) or !Util.exist?(manifest['version']) - @logger.error("The extension manifest's name and version must be defined: #{manifest}, #{extension}") - abort - end - # check the version requirement - if !Util.require_version_valid?(manifest['version'], extension['require_version']) - @logger.error("`#{extension['require_version']}` is required, but current `#{manifest['version']}`: #{extension}") - @logger.error("The current extension version must be updated to satisfy the requirements above") - abort - end + if !Util.exist?(manifest['name']) or !Util.exist?(manifest['version']) + @logger.error("The extension manifest's name and version must be defined: #{manifest}, #{extension}") + abort + end + # check the version requirement + if !Util.require_version_valid?(manifest['version'], extension['require_version']) + @logger.error("`#{extension['require_version']}` is required, but current `#{manifest['version']}`: #{extension}") + @logger.error("The current extension version must be updated to satisfy the requirements above") + abort + end - # check if teracy-dev version satisfies the manifest['target'] if specified - if Util.exist?(manifest['target']) and !Util.require_version_valid?(TeracyDev::VERSION, manifest['target']) - @logger.error("teracy-dev's current version: #{TeracyDev::VERSION}") - @logger.error("this extension requires teracy-dev version: #{manifest['target']} (#{extension})") - abort - end - else - @logger.error("#{manifest_path} must exist for this extension: #{extension}") + # check if teracy-dev version satisfies the manifest['target'] if specified + if Util.exist?(manifest['target']) and !Util.require_version_valid?(TeracyDev::VERSION, manifest['target']) + @logger.error("teracy-dev's current version: #{TeracyDev::VERSION}") + @logger.error("this extension requires teracy-dev version: #{manifest['target']} (#{extension})") abort end end diff --git a/lib/teracy-dev/loader.rb b/lib/teracy-dev/loader.rb index 2318c04b..860516e5 100644 --- a/lib/teracy-dev/loader.rb +++ b/lib/teracy-dev/loader.rb @@ -8,12 +8,11 @@ require_relative 'config/manager' require_relative 'settings/manager' - module TeracyDev class Loader @@instance = nil - attr_reader :processorsManager, :configManager + attr_reader :processorsManager, :configManager, :settings def initialize if !!@@instance @@ -27,7 +26,7 @@ def start @processorsManager = Processors::Manager.new @configManager = Config::Manager.new init_system - settings = build_settings().freeze + @settings = build_settings().freeze require_teracy_dev_version(settings['teracy-dev']['require_version']) configure_vagrant(settings) end