class Blufin::YmlMavenValidator
Constants
- APP_INFRASTRUCTURE
- APP_INFRASTRUCTURE_API
- APP_INFRASTRUCTURE_BUILD_PLUGINS
- APP_INFRASTRUCTURE_CRON
- APP_INFRASTRUCTURE_LIB
- APP_INFRASTRUCTURE_SDK_CORE
- APP_INFRASTRUCTURE_SDK_INTERNAL
- APP_INFRASTRUCTURE_SDK_OAUTH
- APP_INFRASTRUCTURE_WORKER
- BLUFIN
- BLUFIN_PARENT
- BLUFIN_TITLE
- CONFIG
- CONFIG_APP_VERSION
- CONFIG_BLUFIN
- CONFIG_BLUFIN_VERSION
- CONFIG_JAVA
- CONFIG_JAVA_VERSION
- CONFIG_PARENTS
- CONFIG_PARENTS_NAME
- CONFIG_PARENTS_TITLE
- DEPENDENCIES_APP
- DEPENDENCIES_ARTIFACT_ID
- DEPENDENCIES_BLUFIN
- DEPENDENCIES_EXCLUDE
- DEPENDENCIES_GROUP_ID
- DEPENDENCIES_MVN
- DEPENDENCIES_TEST_JAR
- DEPENDENCIES_TEST_SCOPE
- DEPENDENCIES_USE
- DEPENDENCIES_VERSION
- EXTRA_DATA
- EXTRA_DATA_CORE_LIBS
- EXTRA_DATA_CORE_LIBS_PARENTS
- EXTRA_DATA_CORE_LIBS_WITH_CHILDREN
- EXTRA_DATA_MVN_CACHE
- STRUCTURE_APP
- STRUCTURE_BLUFIN
- TYPE_APP
- TYPE_BLUFIN
Attributes
Public Class Methods
Initialize the class. @return void
# File lib/core/yml/maven/yml_maven_validator.rb, line 746 def initialize(site, error_handler) @error_handler = error_handler @config_file_blufin = "#{Blufin::Config::get_path('Paths', 'BlufinJava')}/maven.yml" unless site.nil? @site = Blufin::SiteResolver::validate_site(site) @site_path = Blufin::SiteResolver::get_site_location(@site) @site_name = Blufin::SiteResolver::get_site_name(@site) @site_title = Blufin::SiteResolver::get_site_title(@site) @site_domain = Blufin::SiteResolver::get_site_domain(@site) @config_file_app = "#{Blufin::SiteResolver::get_site_location(@site)}/#{Blufin::YmlMavenValidator::APP_INFRASTRUCTURE}/maven.yml" return unless Blufin::YmlCommon::validate_directory_structure(@site_path, Blufin::Site::PATH_TO_YML_CONFIG, %w(config.yml), [], @error_handler) end # Parse BLUFIN maven.yml. error_count_before = @error_handler.get_error_count @data = validate_single_file(site, @config_file_blufin, STRUCTURE_BLUFIN, error_handler) return false if @data.nil? || @error_handler.get_error_count > error_count_before @data = @data[@config_file_blufin] @data_blufin = validate_yml_file(@config_file_blufin, TYPE_BLUFIN) unless site.nil? @core_libraries = nil @core_libraries_with_children = nil # Parse APP-INFRASTRUCTURE maven.yml. error_count_before = @error_handler.get_error_count @data = validate_single_file(site, @config_file_app, alter_structure_for_app(STRUCTURE_APP), error_handler) return false if @data.nil? || @error_handler.get_error_count > error_count_before @data = @data[@config_file_app] @data_app = validate_yml_file(@config_file_app, TYPE_APP) end end
Private Instance Methods
Alter's the APP-STRUCTURE Hash for this particular site (IE: TaskBot). @return Array
# File lib/core/yml/maven/yml_maven_validator.rb, line 875 def alter_structure_for_app(structure) structure[0][:section_data] = { CONFIG_JAVA => structure[0][:section_data][CONFIG_JAVA], CONFIG_BLUFIN => structure[0][:section_data][CONFIG_BLUFIN], @site_name => structure[0][:section_data][@site_name] = { :type => Blufin::YmlValidatorBase::FIELD_TYPE_NESTED_DATA, :required => true, :section_data => { CONFIG_BLUFIN_VERSION => { :type => FIELD_TYPE_TEXT, :required => true, :regex => /\A[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,4}(-SNAPSHOT)?\z/ } } }, CONFIG_PARENTS => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_ARRAY, :required => false, :section_data => { CONFIG_PARENTS_NAME => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :regex => /\A(#{@site_name})-[a-z\-]+\z/ }, CONFIG_PARENTS_TITLE => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :regex => /\A(#{@site_title})\s[A-Za-z0-9\-()\s]+\z/ }, } } } app_idx = nil # The index of the key in APP_STRUCTURE for which to make changes. structure.each_with_index { |n, idx| app_idx = idx if n[:section_name] == APP_INFRASTRUCTURE } app_hash = {} structure[app_idx][:section_data].keys.each do |key| base_config = structure[app_idx][:section_data][key] base_config[:section_data][BLUFIN_TITLE][:regex] = /\A(#{@site_title})\s[A-Za-z0-9\-()\s]+\z/ base_config[:section_data][BLUFIN_PARENT][:regex] = /\A(#{@site_name})-[a-z\-]+\z/ app_hash["#{@site_name}-#{key}"] = base_config end structure[app_idx][:section_name] = @site_name structure[app_idx][:section_data] = app_hash structure end
Throw error if not in alphabetical order. @return void
# File lib/core/yml/maven/yml_maven_validator.rb, line 994 def check_modules_are_alphabetical_and_not_duplicated(modules, section, field, type) modules = modules.dup config_file = type == TYPE_BLUFIN ? @config_file_blufin : @config_file_app # CHECK FOR DUPLICATES (Must come BEFORE A-Z check). modules_dup = modules.select { |n| modules.count(n) > 1 } modules_dup.uniq! if modules_dup.length > 0 modules_dup.each do |duplicate| @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_DUPLICATE, config_file, section, field, duplicate) end end # CHECK IF IN ALPHABETICAL ORDER modules.uniq! modules_sorted = modules.sort modules.each_with_index do |mvn_module, idx| if modules_sorted[idx] != mvn_module @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_ORDER, config_file, section, field, mvn_module) return end end end
Returns the group “suffix” (if any) for core libs – or NIL. @return Hash
# File lib/core/yml/maven/yml_maven_validator.rb, line 1121 def get_core_lib_suffix(core_lib_name) @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS_WITH_CHILDREN].each do |core_lib_with_child| if core_lib_name =~ /\A#{core_lib_with_child}-/ return core_lib_with_child.gsub(/\Ablufin-/, '') end end nil end
Gets an Array of core libs. @return Array
# File lib/core/yml/maven/yml_maven_validator.rb, line 1018 def get_core_libraries(site_path, type) if @core_libraries.nil? core_libraries = [] core_libraries_with_children = get_core_libraries_with_children(type) Blufin::Files::get_dirs_in_dir(site_path).each do |path| path = get_path_fragment(path) if core_libraries_with_children.include?(path) Blufin::Files::get_dirs_in_dir("#{site_path}/#{path}").each do |path| path = get_path_fragment(path) core_libraries << path unless path == 'target' end else core_libraries << path unless path == 'target' end end @core_libraries = core_libraries end @core_libraries end
Returns an Array of colon (:) separated dependencies from all the internal dependencies. @return Array
# File lib/core/yml/maven/yml_maven_validator.rb, line 1067 def get_core_libraries_as_pair pairs = [] @data[BLUFIN].each do |key, data| if data.has_key?(BLUFIN_PARENT) pairs << "org.blufin.#{get_core_lib_suffix(key).gsub('-', '.')}:#{key}" else pairs << "org.blufin:#{key}" end end pairs end
Gets an Array of all libraries which have children. @return Array
# File lib/core/yml/maven/yml_maven_validator.rb, line 1040 def get_core_libraries_with_children(type) if @core_libraries_with_children.nil? parent_keys = @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS_PARENTS].keys non_existent_parents = [] core_libraries_with_children = [] @data[type == TYPE_BLUFIN ? BLUFIN : @site_name].each do |key, data| if data.has_key?(BLUFIN_PARENT) parent = data[BLUFIN_PARENT] core_libraries_with_children << parent non_existent_parents << [parent, key] unless parent_keys.include?(parent) end end config_file = type == TYPE_BLUFIN ? @config_file_blufin : @config_file_app if non_existent_parents.any? non_existent_parents.each do |nep| @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_UNDEFINED_PARENT, config_file, nep[1], BLUFIN_PARENT, nep[0]) unless parent_keys.include?(nep[0]) end end core_libraries_with_children.sort! core_libraries_with_children.uniq! @core_libraries_with_children = core_libraries_with_children end @core_libraries_with_children end
Returns and Array of formatted modules & checks there are no duplicates. @return Array
# File lib/core/yml/maven/yml_maven_validator.rb, line 922 def get_mvn_modules_and_check_for_duplicates(dependencies, config_file, dependencies_for_error) mvn_modules = [] dependencies.each do |mvn_module| group = '' artifact = '' mvn_module.each do |mmi| group = mmi.values[0] if mmi.keys[0] == DEPENDENCIES_GROUP_ID artifact = mmi.values[0] if mmi.keys[0] == DEPENDENCIES_ARTIFACT_ID end raise RuntimeError, 'group should never be nil!' if group.nil? raise RuntimeError, 'artifact should never be nil!' if artifact.nil? group_artifact = "#{group}:#{artifact}" if mvn_modules.include?(group_artifact) @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_DUPLICATE, config_file, data_key, dependencies_for_error, group_artifact) next end mvn_modules << group_artifact end mvn_modules end
Turns path/to/blufin-core -> blufin-core @return String
# File lib/core/yml/maven/yml_maven_validator.rb, line 1081 def get_path_fragment(path) path = path.split('/') path[path.length - 1] end
Caches MVN dependencies. @return Hash
# File lib/core/yml/maven/yml_maven_validator.rb, line 1088 def map_dependencies(data_map_key) cache = {} dep_data = @data[data_map_key] if dep_data.is_a?(Array) || dep_data.length > 0 dep_data.each do |dep| dep_hash = {} dep.each do |dep_inner| key = dep_inner.keys[0] val = dep_inner.values[0] case key when DEPENDENCIES_GROUP_ID dep_hash[:group] = val when DEPENDENCIES_ARTIFACT_ID dep_hash[:artifact] = val when DEPENDENCIES_VERSION dep_hash[:version] = val when DEPENDENCIES_EXCLUDE dep_hash[:exclude] = val else raise RuntimeError, "Unrecognized key: #{key}" end end raise RuntimeError, ":group must be defined: #{dep_hash.inspect}" if dep_hash[:group].nil? raise RuntimeError, ":artifact must be defined: #{dep_hash.inspect}" if dep_hash[:artifact].nil? raise RuntimeError, ":version must be defined: #{dep_hash.inspect}" if dep_hash[:version].nil? cache["#{dep_hash[:group]}:#{dep_hash[:artifact]}"] = dep_hash end end cache end
Validate order of dependencies. @return void
# File lib/core/yml/maven/yml_maven_validator.rb, line 945 def validate_dependencies_are_alphabetical_and_exist(data, field, section_type, section, type) if data.is_a?(Array) && data.length > 0 config_file = type == TYPE_BLUFIN ? @config_file_blufin : @config_file_app modules = [] data.each do |data_inner| data_inner.each do |di| if di.keys[0] == DEPENDENCIES_USE val = di.values[0] case section_type when DEPENDENCIES_BLUFIN if type == TYPE_BLUFIN @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_NOT_REGISTERED, config_file, section, field, val) unless @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS].include?(val) else # TODO - MUST VALIDATE AGAINST CORE-LIBS WHEN LOOPING APP MAVEN.YML end when DEPENDENCIES_MVN @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_NOT_REGISTERED, config_file, section, field, val) unless @data[EXTRA_DATA][EXTRA_DATA_MVN_CACHE].keys.include?(val) else raise RuntimeError, "Unrecognized section-type: #{field}" end modules << val end end end # CHECK FOR DUPLICATES (Must come BEFORE A-Z check). modules_dup = modules.select { |n| modules.count(n) > 1 } modules_dup.uniq! # TODO - This is commented out because blufin-api needs blufin-core as a regular dependency and a '<type>test-jar</type>' (for the Mocks). This flags it as a duplicate. # if modules_dup.length > 0 # modules_dup.each do |duplicate| # @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_DUPLICATE, config_file, section, field, duplicate) # end # end # CHECK IF IN ALPHABETICAL ORDER modules.uniq! modules_sorted = modules.sort modules.each_with_index do |mvn_module, idx| if modules_sorted[idx] != mvn_module @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_ORDER, config_file, section, field, mvn_module) return end end end end
Custom validation only applicable to MAVEN YML definition(s) - BLUFIN
. @return void
# File lib/core/yml/maven/yml_maven_validator.rb, line 792 def validate_yml_file(config_file, type) @data[EXTRA_DATA] = {} @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS_PARENTS] = {} @data[DEPENDENCIES_MVN] = [] if @data[DEPENDENCIES_MVN].nil? # CACHE PARENT DEFINITIONS. if @data[CONFIG].has_key?(CONFIG_PARENTS) @data[CONFIG][CONFIG_PARENTS].each do |parent_definition| name = nil title = nil parent_definition.each do |pd| key = pd.keys[0] value = pd.values[0] if key == CONFIG_PARENTS_NAME name = value elsif key == CONFIG_PARENTS_TITLE title = value end end raise RuntimeError, 'name was empty, this should never happen!' if name.nil? raise RuntimeError, 'title was empty, this should never happen!' if title.nil? @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS_PARENTS][name] = { :title => title } end end if type == TYPE_BLUFIN # CHECK FOR DUPLICATES (blufin-java). mvn_modules_internal = get_mvn_modules_and_check_for_duplicates(@data[DEPENDENCIES_MVN], config_file, DEPENDENCIES_MVN) # CHECK MODULES ARE IN ALPHABETICAL ORDER (blufin-java). check_modules_are_alphabetical_and_not_duplicated(mvn_modules_internal, DEPENDENCIES_MVN, nil, type) else @data_blufin[DEPENDENCIES_MVN].each do |bsd| asd_found = false if @data[DEPENDENCIES_MVN].any? bsd_extract = Blufin::YmlCommon::extract_group_artifact_version_from_array(bsd) @data[DEPENDENCIES_MVN].each do |asd| asd_extract = Blufin::YmlCommon::extract_group_artifact_version_from_array(asd) asd_found = true if "#{bsd_extract[DEPENDENCIES_GROUP_ID]}:#{bsd_extract[DEPENDENCIES_ARTIFACT_ID]}" == "#{asd_extract[DEPENDENCIES_GROUP_ID]}:#{asd_extract[DEPENDENCIES_ARTIFACT_ID]}" end end @data[DEPENDENCIES_MVN] << bsd unless asd_found end end @data[EXTRA_DATA][EXTRA_DATA_MVN_CACHE] = map_dependencies(DEPENDENCIES_MVN) @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS] = get_core_libraries(type == TYPE_BLUFIN ? Blufin::Config::get_path('Paths', 'BlufinJava') : "#{@site_path}/#{APP_INFRASTRUCTURE}", type) @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS_WITH_CHILDREN] = get_core_libraries_with_children(type) # ADD ERROR FOR UNUSED PARENTS. @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS_PARENTS].keys.each { |n| @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_UNUSED_PARENT, config_file, CONFIG, CONFIG_PARENTS, n) unless @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS_WITH_CHILDREN].include?(n) } # VALIDATE CORE core_libraries = @data[EXTRA_DATA][EXTRA_DATA_CORE_LIBS] core_modules = [] data_key = type == TYPE_BLUFIN ? BLUFIN : @site_name @data[data_key].each do |key, data| validate_dependencies_are_alphabetical_and_exist(data[DEPENDENCIES_BLUFIN], "#{key}.#{DEPENDENCIES_BLUFIN}", DEPENDENCIES_BLUFIN, data_key, type) validate_dependencies_are_alphabetical_and_exist(data[DEPENDENCIES_MVN], "#{key}.#{DEPENDENCIES_MVN}", DEPENDENCIES_MVN, data_key, type) @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_UNRECOGNIZED, config_file, data_key, key, key) unless core_libraries.include?(key) core_modules << key end core_libraries.each do |core_library| @error_handler.add_error(Blufin::YmlErrorHandler::MAVEN_MODULE_NOT_DEFINED, config_file, data_key, nil, core_library) unless core_modules.include?(core_library) end @data end