diff --git a/src/gewf/gewf-safe.ecf b/src/gewf/gewf-safe.ecf deleted file mode 100644 index cc243148..00000000 --- a/src/gewf/gewf-safe.ecf +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - /.git$ - /EIFGENs$ - /.svn$ - - - - - - - diff --git a/src/gewf/gewf.ecf b/src/gewf/gewf.ecf index 3213ca47..140da892 100644 --- a/src/gewf/gewf.ecf +++ b/src/gewf/gewf.ecf @@ -1,16 +1,21 @@ - + + Generator for EWF project /.git$ /EIFGENs$ /.svn$ - + - - + + + + + diff --git a/src/gewf/src/gewf.e b/src/gewf/src/gewf.e index 7e805323..f0140dba 100644 --- a/src/gewf/src/gewf.e +++ b/src/gewf/src/gewf.e @@ -14,19 +14,146 @@ feature {NONE} -- Initialization make -- Initialize `Current'. + local + args: ARGUMENTS_32 + cfg: detachable READABLE_STRING_32 do - + create args + if args.argument_count > 0 then + cfg := args.argument (1) + end + if cfg /= Void then + load_configuration (cfg) + end + execute end feature -- Status feature -- Access -feature -- Change + config (k: READABLE_STRING_GENERAL): detachable READABLE_STRING_32 + local + l_keys: LIST [READABLE_STRING_GENERAL] + do + if attached {JSON_STRING} json_item (json, k) as js then + Result := js.unescaped_string_32 + end + end + + json_item (j: detachable JSON_VALUE; k: READABLE_STRING_GENERAL): detachable JSON_VALUE + local + l_keys: LIST [READABLE_STRING_GENERAL] + v: detachable JSON_VALUE + s: STRING_32 + js: JSON_STRING + do + if attached {JSON_OBJECT} j as jo then + l_keys := k.split ('.') + l_keys.start + create js.make_json_from_string_32 (l_keys.item.as_readable_string_32) + v := jo.item (js) + l_keys.remove + if l_keys.count > 0 then + if v /= Void then + create s.make (k.count) + across + l_keys as c + loop + s.append_string_general (c.item) + s.append_character ('.') + end + s.remove_tail (1) + Result := json_item (v, s) + end + else + Result := v + end + end + end + + load_configuration (fn: READABLE_STRING_GENERAL) + local + p: JSON_PARSER + f: PLAIN_TEXT_FILE + s: STRING + do + create s.make (1_024) + + create f.make_with_name (fn) + if f.exists and then f.is_access_readable then + f.open_read + from + until + f.exhausted + loop + f.read_stream_thread_aware (1_024) + s.append (f.last_string) + end + f.close + end + + create p.make_parser (s) + json := p.parse + end + + json: detachable JSON_VALUE + +feature -- Execution + + execute + local + tpl_name: READABLE_STRING_32 + vals: STRING_TABLE [READABLE_STRING_8] + uuid_gen: UUID_GENERATOR + do + if attached config ("template") as s32 then + create vals.make (5) + + tpl_name := s32 + create uuid_gen + vals.force (uuid_gen.generate_uuid.out, "UUID") + + if + attached config ("application.name") as appname + then + vals.force (appname.to_string_8, "APPNAME") + else + vals.force ("application", "APPNAME") + end + + if + attached config ("application.root_class") as approot + then + vals.force (approot.to_string_8, "APP_ROOT") + else + vals.force ("APPLICATION", "APP_ROOT") + end + generate (tpl_name, vals) + else + io.error.put_string ("Error no template value! %N") + end + end + + generate (tpl: READABLE_STRING_32; vals: STRING_TABLE [READABLE_STRING_8]) + local + gen: GEWF_GENERATOR + p: PATH + appname: detachable READABLE_STRING_GENERAL + do + create p.make_from_string ("template") + p := p.extended (tpl) + appname := vals.item ("APPNAME") + if appname = Void then + appname := "_generated" + end + create gen.make (p, create {PATH}.make_from_string (appname)) + gen.execute (vals) + end feature {NONE} -- Implementation invariant --- invariant_clause: True +-- invariant_clause: True end diff --git a/src/gewf/src/gewf_generator.e b/src/gewf/src/gewf_generator.e new file mode 100644 index 00000000..91312a39 --- /dev/null +++ b/src/gewf/src/gewf_generator.e @@ -0,0 +1,122 @@ +note + description: "Summary description for {GEWF_GENERATOR}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + GEWF_GENERATOR + +inherit + DIRECTORY_ITERATOR + redefine + process_directory, + process_file + end + +create + make + +feature {NONE} -- Initialization + + make (tpl: PATH; tgt: PATH) + do + template_folder := tpl + target_folder := tgt + end + +feature -- Execution + + execute (vals: STRING_TABLE [READABLE_STRING_8]) + do + values := vals + process_directory (template_folder) + values := Void + end + +feature -- Operation + + process_file (fn: PATH) + -- + local + s: STRING_32 + line: STRING + src,tgt: RAW_FILE + do + create s.make_from_string (fn.name) + s := s.substring (template_folder.name.count + 2, s.count) + if attached fn.extension as ext and then ext.is_case_insensitive_equal ("tpl") then + s.remove_tail (4) -- ".tpl" + end + + evaluate_string_32 (s) + s.to_lower + create src.make_with_path (fn) + create tgt.make_with_path (target_folder.extended (s)) + tgt.create_read_write + src.open_read + from + until + src.exhausted + loop + src.read_line_thread_aware + line := src.last_string + evaluate_string_8 (line) + tgt.put_string (line) + tgt.put_new_line + end + src.close + tgt.close + +-- Precursor (fn) + end + + process_directory (dn: PATH) + -- + local + s: STRING_32 + p: PATH + dir: DIRECTORY + do + create s.make_from_string (dn.name) + s := s.substring (template_folder.name.count + 1, s.count) + evaluate_string_32 (s) + p := target_folder.extended (s) + create dir.make_with_path (p) + dir.recursive_create_dir + Precursor (dn) + end + +feature -- Access + + values: detachable STRING_TABLE [READABLE_STRING_8] + + template_folder: PATH + target_folder: PATH + +feature -- Implementation + + evaluate_string_8 (s: STRING_8) + do + if attached values as l_values then + across + l_values as c + loop + s.replace_substring_all ({STRING_8} "${" + c.key.as_string_8 + "}", c.item) + end + end + end + + evaluate_string_32 (s: STRING_32) + do + if attached values as l_values then + across + l_values as c + loop + s.replace_substring_all ({STRING_32} "${" + c.key.as_string_32 + "}", c.item) + end + end + end + + +end diff --git a/src/gewf/template/basic/project.ecf.tpl b/src/gewf/template/basic/${APPNAME}.ecf.tpl similarity index 91% rename from src/gewf/template/basic/project.ecf.tpl rename to src/gewf/template/basic/${APPNAME}.ecf.tpl index 3fe8bac0..d293c122 100644 --- a/src/gewf/template/basic/project.ecf.tpl +++ b/src/gewf/template/basic/${APPNAME}.ecf.tpl @@ -1,6 +1,6 @@ - + /EIFGENs$ /CVS$ @@ -13,7 +13,7 @@ - + @@ -21,19 +21,19 @@ - + - + - + diff --git a/src/gewf/template/basic/project.ecf b/src/gewf/template/basic/project.ecf deleted file mode 100644 index ff9b4ab7..00000000 --- a/src/gewf/template/basic/project.ecf +++ /dev/null @@ -1,44 +0,0 @@ - - - - - /EIFGENs$ - /CVS$ - /.svn$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gewf/template/basic/src/app_service.e b/src/gewf/template/basic/src/${APP_ROOT}.e.tpl similarity index 92% rename from src/gewf/template/basic/src/app_service.e rename to src/gewf/template/basic/src/${APP_ROOT}.e.tpl index 23caa88a..d93b9ef5 100644 --- a/src/gewf/template/basic/src/app_service.e +++ b/src/gewf/template/basic/src/${APP_ROOT}.e.tpl @@ -6,7 +6,7 @@ note revision: "$Revision$" class - APPLICATION + ${APP_ROOT} inherit WSF_LAUNCHABLE_SERVICE @@ -34,7 +34,6 @@ feature {NONE} -- Initialization setup_router -- Setup `router' local - doc: WSF_ROUTER_SELF_DOCUMENTATION_HANDLER fhdl: WSF_FILE_SYSTEM_HANDLER do router.handle_with_request_methods ("/doc", create {WSF_ROUTER_SELF_DOCUMENTATION_HANDLER}.make (router), router.methods_GET) diff --git a/src/gewf/testing/README.txt b/src/gewf/testing/README.txt new file mode 100644 index 00000000..1d7b2986 --- /dev/null +++ b/src/gewf/testing/README.txt @@ -0,0 +1,9 @@ +To generate "demo" + + +gewf demo.cfg + + +It will generate the project under demo\demo.ecf + +note for now, the "template" folder should be in the current folder. diff --git a/src/gewf/testing/demo.cfg b/src/gewf/testing/demo.cfg new file mode 100644 index 00000000..545f164c --- /dev/null +++ b/src/gewf/testing/demo.cfg @@ -0,0 +1,4 @@ +{ +"template": "basic", +"application": {"name" : "demo", "root_class": "EWF_DEMO" } +}