From 46221844659e32a233fd066d158e29ae57990835 Mon Sep 17 00:00:00 2001 From: wolandscat Date: Thu, 1 Feb 2024 13:32:39 -0700 Subject: [PATCH] Add matching archetypes function to library. --- .../src/interface/archetype_compiler.e | 18 ++++++++++ .../src/library/archetype_library.e | 36 ++++++++++++++----- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/components/adl_compiler/src/interface/archetype_compiler.e b/components/adl_compiler/src/interface/archetype_compiler.e index 1bbb12705..0caf8ca2e 100755 --- a/components/adl_compiler/src/interface/archetype_compiler.e +++ b/components/adl_compiler/src/interface/archetype_compiler.e @@ -85,6 +85,24 @@ feature -- Commands build_lineage (ara, 0) end + build_matching_artefacts (id_regex: STRING) + -- top entry point into a compile run for archetypes matching an id regex + local + regex_matcher: RX_PCRE_REGULAR_EXPRESSION + do + create regex_matcher.make + regex_matcher.set_case_insensitive (True) + regex_matcher.compile (id_regex) + if regex_matcher.is_compiled then + run_list.wipe_out + across current_library.matching_archetypes (id_regex, Void, Void) as aras_csr loop + build_lineage (aras_csr.item, 0) + end + else + call_console_update_agent (get_msg_line ({ADL_MESSAGES_IDS}.ec_regex_e1, <>)) + end + end + feature {NONE} -- Build State from_scratch: BOOLEAN diff --git a/components/archetype_repository/src/library/archetype_library.e b/components/archetype_repository/src/library/archetype_library.e index 9494b5acc..0560f60a1 100755 --- a/components/archetype_repository/src/library/archetype_library.e +++ b/components/archetype_repository/src/library/archetype_library.e @@ -177,19 +177,41 @@ feature -- Access Regex_valid: not a_regex.is_empty Rm_type_valid: attached an_rm_type as att_rm_type implies not att_rm_type.is_empty Rm_closure_valid: attached an_rm_package as att_rm_closure implies not att_rm_closure.is_empty + do + create Result.make (0) + Result.compare_objects + across matching_archetypes (a_regex, an_rm_type, an_rm_package) as archs_csr loop + Result.extend (archs_csr.key.to_string_8) + end + + if Result.count = 0 then + regex_matcher.compile (a_regex) + if not regex_matcher.is_compiled then + Result.extend (get_msg_line (ec_regex_e1, <>)) + end + end + end + + matching_archetypes (a_regex: STRING; an_rm_type, an_rm_package: detachable STRING): STRING_TABLE [ARCH_LIB_ARCHETYPE] + -- generate list of archetype ids that lexically match the regex pattern and optional rm_type. If rm_type is supplied, + -- we assume that the regex itself does not contain an rm type. Matching using `an_rm_type' and + -- `an_rm_package' is done in lower case. Any case may be supplied for these two + require + Regex_valid: not a_regex.is_empty + Rm_type_valid: attached an_rm_type as att_rm_type implies not att_rm_type.is_empty + Rm_closure_valid: attached an_rm_package as att_rm_closure implies not att_rm_closure.is_empty local arch_id: ARCHETYPE_HRID is_candidate: BOOLEAN - rm_type, rm_closure: detachable STRING + rm_type, rm_package: detachable STRING do create Result.make (0) - Result.compare_objects if attached an_rm_type as rm_t then rm_type := rm_t.as_lower end - if attached an_rm_package as rm_cl then - rm_closure := rm_cl.as_lower + if attached an_rm_package as rm_pkg then + rm_package := rm_pkg.as_lower end regex_matcher.compile (a_regex) @@ -199,19 +221,17 @@ feature -- Access arch_id := ala.id if attached rm_type as rmt then is_candidate := rmt.is_equal (arch_id.rm_class.as_lower) - if is_candidate and attached rm_closure as rmc then + if is_candidate and attached rm_package as rmc then is_candidate := rmc.is_equal (arch_id.rm_package.as_lower) end else is_candidate := True end if is_candidate then - Result.extend (arch_id.physical_id) + Result.put (ala, arch_id.physical_id) end end end - else - Result.extend (get_msg_line (ec_regex_e1, <>)) end end