First working (but limited) tool

This commit is contained in:
2013-07-05 15:06:30 +02:00
parent 5b988ab760
commit eea8894724
9 changed files with 280 additions and 74 deletions

View File

@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="gewf" uuid="2D4957D5-77D3-4EC7-BF80-E4E6AC7A3EF3">
<target name="gewf">
<root class="GEWF" feature="make"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<setting name="concurrency" value="none"/>
<library name="base" location="$ISE_LIBRARY/library/base/base-safe.ecf"/>
<cluster name="src" location="src" recursive="true"/>
</target>
</system>

View File

@@ -1,16 +1,21 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-8-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-8-0 http://www.eiffel.com/developers/xml/configuration-1-8-0.xsd" name="gewf" uuid="2D4957D5-77D3-4EC7-BF80-E4E6AC7A3EF3">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-11-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-11-0 http://www.eiffel.com/developers/xml/configuration-1-11-0.xsd" name="gewf" uuid="2D4957D5-77D3-4EC7-BF80-E4E6AC7A3EF3">
<target name="gewf">
<description>Generator for EWF project </description>
<root class="GEWF" feature="make"/>
<file_rule>
<exclude>/.git$</exclude>
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" void_safety="none" syntax="standard">
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="transitional" syntax="standard">
</option>
<setting name="executable_name" value="gewf"/>
<setting name="concurrency" value="none"/>
<library name="base" location="$ISE_LIBRARY/library/base/base.ecf"/>
<cluster name="src" location="." recursive="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="base_extension" location="$ISE_LIBRARY\library\base_extension\base_extension-safe.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json-safe.ecf"/>
<library name="uuid" location="$ISE_LIBRARY\library\uuid\uuid-safe.ecf"/>
<cluster name="src" location="src\" recursive="true"/>
</target>
</system>

View File

@@ -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

View File

@@ -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)
-- <Precursor>
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)
-- <Precursor>
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

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="${APPNAME}" uuid="${UUID}" library_target="${APPNAME}">
<target name="_common" abstract="true">
<target name="common" abstract="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
@@ -13,7 +13,7 @@
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
</target>
<target name="${APPNAME}_any" extends="_common">
<target name="${APPNAME}_any" extends="common">
<root class="${APP_ROOT}" feature="make_and_launch"/>
<library name="cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\connector\cgi-safe.ecf"/>
<library name="libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\connector\libfcgi-safe.ecf"/>
@@ -21,19 +21,19 @@
<cluster name="launcher" location=".\launcher\any\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="${APPNAME}_nino" extends="_common">
<target name="${APPNAME}_nino" extends="common">
<root class="${APP_ROOT}" feature="make_and_launch"/>
<library name="default_nino" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\nino-safe.ecf"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="${APPNAME}_cgi" extends="_common">
<target name="${APPNAME}_cgi" extends="common">
<root class="${APP_ROOT}" feature="make_and_launch"/>
<library name="default_cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\cgi-safe.ecf"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="${APPNAME}_libfcgi" extends="_common">
<target name="${APPNAME}_libfcgi" extends="common">
<root class="${APP_ROOT}" feature="make_and_launch"/>
<library name="default_libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\libfcgi-safe.ecf"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>

View File

@@ -1,44 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-11-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-11-0 http://www.eiffel.com/developers/xml/configuration-1-11-0.xsd" name="appname" uuid="68F1B110-A242-47A1-95D8-63428E40A633" library_target="appname">
<target name="server" abstract="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="transitional" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf" readonly="false"/>
</target>
<target name="appname_any" extends="server">
<root class="APPLICATION" feature="make_and_launch"/>
<library name="cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\connector\cgi-safe.ecf"/>
<library name="libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\connector\libfcgi-safe.ecf"/>
<library name="nino" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\connector\nino-safe.ecf"/>
<cluster name="launcher" location=".\launcher\any\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="appname_nino" extends="server">
<root class="APPLICATION" feature="make_and_launch"/>
<library name="default_nino" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\nino-safe.ecf"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="appname_cgi" extends="server">
<root class="APPLICATION" feature="make_and_launch"/>
<library name="default_cgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\cgi-safe.ecf"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="appname_libfcgi" extends="server">
<root class="APPLICATION" feature="make_and_launch"/>
<library name="default_libfcgi" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\default\libfcgi-safe.ecf"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
<target name="appname" extends="appname_nino">
</target>
</system>

View File

@@ -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)

View File

@@ -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.

View File

@@ -0,0 +1,4 @@
{
"template": "basic",
"application": {"name" : "demo", "root_class": "EWF_DEMO" }
}