Added simple console wizard for Eiffel Studio.

(It is not very user friendly, this is a first draft)
It should be improved in the future (with GUI, ...)
This commit is contained in:
Jocelyn Fiat
2012-06-22 15:54:50 +02:00
parent 87c2074d2b
commit 9b13aa27dd
14 changed files with 843 additions and 0 deletions

View File

@@ -10,6 +10,37 @@ For instance
Update
: git pull -s subtree ewf_wiki master
Reconnect subtree from a cloned repository
- doc/wiki
git remote add -f ewf_wiki https://github.com/EiffelWebFramework/EWF.wiki.git
git merge -s ours --no-commit --squash ewf_wiki/master
git pull -s subtree ewf_wiki master
- contrib/ise_library/cURL
git remote add -f ewf_curl https://github.com/EiffelSoftware/mirror-Eiffel-cURL.git
git merge -s ours --no-commit --squash ewf_curl/master
git pull -s subtree ewf_curl master
- contrib/library/text/parser/json
git remote add -f ewf_json https://github.com/eiffelhub/json.git
git merge -s ours --no-commit --squash ewf_json/master
git pull -s subtree ewf_json master
- contrib/library/network/server/nino
git remote add -f ewf_nino https://github.com/Eiffel-World/EiffelWebNino.git
git merge -s ours --no-commit --squash ewf_nino/master
git pull -s subtree ewf_nino master
When there are troubles ... to pull subtree from a cloned repository
git remote add -f ewf_nino https://github.com/Eiffel-World/EiffelWebNino.git
git merge -s ours --no-commit --squash ewf_nino/master
git checkout ewf_nino/master -b ewf_nino
git pull ewf_nino master
git checkout master
git merge --squash -s subtree --no-commit ewf_nino/master
Note ... even if git is working great also on Windows
It might occurs that handling the subtree pulling fails on Windows, and works
on Linux. So I would advice to use Linux to manipulate those subtree
operation.
= remove git submodule =
1. Delete the relevant section from the .gitmodules file.
@@ -23,3 +54,18 @@ Ex:
: git rm --cached doc/wiki
: git commit -m "Removed submodule doc/wiki"
= Remove remote tag =
: git pull # to marge changes from others
: git tag -d v0.1 # delete the tag
: git push origin :refs/tags/v0.1 # this remove tag from remote repository
: git tag -a v0.1 "First official version" # this mark the most recent commit
: git push origin v0.1 # push a new tag position to remote repository
= git branches and remote =
* git push origin my_branch #push local my_branch to the remote "origin"
* git push origin :my_branch #delete remote branch "my_branch" from "origin"
* git branch -d my_branch #delete local branch "my_branch"
* Then from another local repository, you can get this new branch using
: git fetch origin
: git checkout --track origin/my_branch -b my_branch

4
tools/ise_wizard/ewf.dsc Normal file
View File

@@ -0,0 +1,4 @@
NAME="Eiffel Web Framework application, multi-platform, with EWF"
DESCRIPTION="Create a web server application based on the cross-platform library EWF."
LOCATION="ewf"
PLATFORM="all"

View File

@@ -0,0 +1,18 @@
<?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="ewf_ise_wizard" uuid="F881A707-745E-4C6D-90D1-F820EE3B1470">
<target name="ewf_ise_wizard">
<root class="EWF_WIZARD" 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"/>
<library name="uuid" location="$ISE_LIBRARY\library\uuid\uuid-safe.ecf"/>
<library name="vision2" location="$ISE_LIBRARY\library\vision2\vision2-safe.ecf"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,19 @@
setlocal
rd /q/s tmp
mkdir tmp
ecb -config ewf_ise_wizard-safe.ecf -finalize -c_compile -project_path tmp
mkdir spec
mkdir spec\%ISE_PLATFORM%
move tmp\EIFGENs\ewf_ise_wizard\F_code\ewf_ise_wizard.exe spec\%ISE_PLATFORM%\wizard.exe
rd /q/s tmp
set WIZ_TARGET=%ISE_EIFFEL%\studio\wizards\new_projects\ewf
rd /q/s %WIZ_TARGET%
mkdir %WIZ_TARGET%
xcopy /I /E /Y %~dp0\pixmaps %WIZ_TARGET%\pixmaps
xcopy /I /E /Y %~dp0\resources %WIZ_TARGET%\resources
xcopy /I /E /Y %~dp0\spec %WIZ_TARGET%\spec
copy ewf.dsc %WIZ_TARGET%\..\ewf.dsc
endlocal

View File

@@ -0,0 +1,4 @@
# For nino connector, use port ${WIZ:EWF_NINO_PORT}
port=${WIZ:EWF_NINO_PORT}
#verbose=true

View File

@@ -0,0 +1,98 @@
note
description: "[
This class implements the web service
It inherits from WSF_DEFAULT_SERVICE to get default EWF connector ready
And from WSF_URI_TEMPLATE_ROUTED_SERVICE to use the router service
`initialize' can be redefine to provide custom options if needed.
]"
class
EWF_APPLICATION
inherit
WSF_URI_TEMPLATE_ROUTED_SERVICE
WSF_DEFAULT_SERVICE
redefine
initialize
end
create
make_and_launch
feature {NONE} -- Initialization
setup_router
do
-- Set the router here
router.map_agent ("/hello/{user}", agent execute_hello)
end
feature -- Execution
execute_default (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Default request handler if no other are relevant
local
l_url: READABLE_STRING_8
do
-- The following code is provided as example, feel free to replace with your the code
l_url := req.script_url ("/hello/world")
res.redirect_now_with_content (l_url, "Redirection to " + l_url, "text/html")
end
execute_hello (ctx: WSF_URI_TEMPLATE_HANDLER_CONTEXT; req: WSF_REQUEST; res: WSF_RESPONSE)
-- Computed response message.
local
mesg: WSF_HTML_PAGE_RESPONSE
s: STRING_8
l_user_name: READABLE_STRING_32
do
-- The following code is provided as example, feel free to replace with your the code
--| It is now returning a WSF_HTML_PAGE_RESPONSE
--| Since it is easier for building html page
create mesg.make
mesg.set_title ("Hello World!")
--| Check if the request contains a parameter named "user"
--| this could be a query, or a form parameter
if attached {WSF_STRING} req.item ("user") as u then
--| If yes, say hello world #name
l_user_name := (create {HTML_ENCODER}).decoded_string (u.value)
s := "<p>Hello " + mesg.html_encoded_string (l_user_name) + "!</p>"
mesg.set_body (s)
--| We should html encode this name
--| but to keep the example simple, we don't do that for now.
else
--| Otherwise, ask for name
s := (create {HTML_ENCODER}).encoded_string ({STRING_32} "Hello / ahoj / नमस्ते / Ciào / مرحبا / Hola / 你好 / Hallo / Selam / Bonjour ")
s.append ("[
<form action="/hello" method="GET">
What is your name?</p>
<input type="text" name="user"/>
<input type="submit" value="Validate"/>
</form>
]"
)
mesg.set_body (s)
end
res.send (mesg)
end
feature {NONE} -- Initialization
initialize
do
--| The following line is to be able to load options from the file ewf.ini
create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} service_options.make_from_file ("ewf.ini")
--| If you don't need any custom options, you are not obliged to redefine `initialize'
Precursor
--| Initialize router
initialize_router
end
end

View File

@@ -0,0 +1,52 @@
note
description: "[
This class implements the web service
It inherits from WSF_DEFAULT_SERVICE to get default EWF connector ready
It just implements `execute'
`initialize' can be redefine to provide custom options if needed.
]"
class
EWF_APPLICATION
inherit
WSF_DEFAULT_SERVICE
redefine
initialize
end
create
make_and_launch
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Default request handler if no other are relevant
local
mesg: WSF_HTML_PAGE_RESPONSE
s: STRING_8
l_user_name: READABLE_STRING_32
do
create mesg.make
mesg.set_title ("Hello World!")
mesg.set_body ("<h1>Hello World!</h1>")
res.send (mesg)
end
feature {NONE} -- Initialization
initialize
do
--| The following line is to be able to load options from the file ewf.ini
create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} service_options.make_from_file ("ewf.ini")
--| If you don't need any custom options, you are not obliged to redefine `initialize'
Precursor
--| Initialize router
initialize_router
end
end

View File

@@ -0,0 +1,21 @@
<?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="${WIZ:TARGET_NAME}" uuid="${WIZ:UUID}">
<target name="${WIZ:TARGET_NAME}">
<root class="EWF_APPLICATION" feature="make_and_launch"/>
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="transitional">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="concurrency" value="${WIZ:CONCURRENCY}"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="default_${WIZ:EWF_CONNECTOR}" location="$ISE_LIBRARY/contrib/library/web/framework/ewf/wsf/default/${WIZ:EWF_CONNECTOR}-safe.ecf"/>
<library name="encoder" location="$ISE_LIBRARY/contrib/library/web/framework/ewf/text/encoder/encoder-safe.ecf" readonly="false"/>
<library name="wsf" location="$ISE_LIBRARY/contrib/library/web/framework/ewf/wsf/wsf-safe.ecf" readonly="false"/>
<library name="http" location="$ISE_LIBRARY/contrib/library/network/protocol/http/http-safe.ecf" readonly="false"/>
<cluster name="src" location=".\src\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,163 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
class
EWF_WIZARD
inherit
WIZARD
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
initialize
get_information
if is_valid and attached layout as lay then
generate_project (lay)
end
end
feature -- Status
feature -- Access
project_directory_name: detachable READABLE_STRING_8
projet_name: detachable READABLE_STRING_8
use_router: BOOLEAN
router_type: detachable READABLE_STRING_8
connector: detachable READABLE_STRING_8
feature -- Form
get_information
local
e: EXECUTION_ENVIRONMENT
do
create e
project_directory_name := e.get ("ISE_PROJECTS")
if
attached project_directory_name as pdn and then
attached string_question ("Project directory (default=" + pdn + ")? ", <<["q", Void]>>, pdn, False) as r_pdn
then
project_directory_name := r_pdn.string
elseif attached string_question ("Project directory ? ", <<["q", Void]>>, Void, False) as r_pdn then
project_directory_name := r_pdn.string
end
if project_directory_name = Void then
die (-1)
end
if attached string_question ("Project name ? ", Void, Void, False) as pn then
projet_name := pn.string
else
projet_name := "ewf"
end
if boolean_question ("Do you want to use router (Y|n) ? ", <<["y", True], ["Y", True]>>, "Y") then
use_router := True
router_type := "uri-template"
else
use_router := False
end
if attached string_question ("[
Default connector ?
1 - Eiffel Web Nino (standalone web server)
2 - CGI application (requires to setup httpd server)
3 - libFCGI application (requires to setup httpd server)
Your choice:
]", <<["1", "nino"], ["2", "cgi"], ["3", "libfcgi"]>>, "1", True) as conn
then
connector := conn
else
connector := "nino"
end
end
is_valid: BOOLEAN
do
Result := project_directory_name /= Void and projet_name /= Void
end
generate_project (a_layout: WIZARD_LAYOUT)
require
is_valid
local
d: DIRECTORY
dn: DIRECTORY_NAME
tfn: FILE_NAME
res: WIZARD_SUCCEED_RESPONSE
do
if attached project_directory_name as pdn then
if attached projet_name as pn then
variables.force (pn, "TARGET_NAME")
variables.force (new_uuid, "UUID")
variables.force ("none", "CONCURRENCY")
if attached connector as conn then
variables.force (conn, "EWF_CONNECTOR")
end
variables.force ("9999", "EWF_NINO_PORT")
create dn.make_from_string (pdn)
dn.extend (pn)
create d.make (dn.string)
if not d.exists then
d.recursive_create_dir
end
create tfn.make_from_string (dn.string)
tfn.set_file_name (pn)
tfn.add_extension ("ecf")
copy_resource_template ("template.ecf", tfn.string)
create res.make (tfn.string, d.name)
create dn.make_from_string (pdn)
dn.extend (pn)
dn.extend ("src")
create d.make (dn.string)
if not d.exists then
d.recursive_create_dir
end
create tfn.make_from_string (dn.string)
tfn.set_file_name ("ewb_application")
tfn.add_extension ("e")
if attached router_type as rt then
check rt.same_string ("uri-template") end
copy_resource_template ("ewb_application-"+ rt +".e", tfn.string)
else
copy_resource_template ("ewb_application.e", tfn.string)
end
create tfn.make_from_string (dn.string)
tfn.set_file_name ("ewf")
tfn.add_extension ("ini")
copy_resource_template ("ewf.ini", tfn.string)
send_response (res)
end
end
end
feature -- Output
feature {NONE} -- Implementation
invariant
-- invariant_clause: True
end

View File

@@ -0,0 +1,265 @@
note
description : "Objects that ..."
author : "$Author$"
date : "$Date$"
revision : "$Revision$"
deferred class
WIZARD
inherit
ARGUMENTS
feature {NONE} -- Initialization
initialize
-- Initialize `Current'.
local
i,n: INTEGER
s: READABLE_STRING_8
wizard_directory_name: detachable READABLE_STRING_8
callback_file_name: detachable READABLE_STRING_8
do
create variables.make (5)
n := argument_count
if n > 0 then
from
i := 1
until
i > n
loop
s := argument (i)
if s.same_string ("-callback") or s.same_string ("--callback") then
i := i + 1
if i <= n then
callback_file_name := argument (i)
end
elseif wizard_directory_name = Void then
wizard_directory_name := s
else
debug
io.error.put_string ("Ignoring argument %"" + s + "%"%N")
end
end
i := i + 1
end
end
if wizard_directory_name = Void then
display_usage (io.error)
quit ("ERROR: Missing wizard directory name.")
elseif callback_file_name = Void then
display_usage (io.error)
quit ("ERROR: Missing Eiffel Studio callback file name.")
else
create layout.make (wizard_directory_name, callback_file_name)
end
end
feature -- Status
display_usage (f: FILE)
do
f.put_string ("Usage: wizard {dirname} -callback {filename}%N")
f.put_string (" -callback filename: file used to communicate back with Eiffel Studio%N")
f.put_string (" dirname: folder containing the wizard resources, pixmaps, ...%N")
end
quit (m: detachable READABLE_STRING_8)
do
if m /= Void then
io.error.put_string (m)
end
send_response (create {WIZARD_FAILED_RESPONSE})
ensure
False -- never reached
end
die (code: INTEGER)
do
(create {EXCEPTIONS}).die (code)
end
feature -- Access
variables: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
layout: detachable WIZARD_LAYOUT
feature -- Response
send_response (res: WIZARD_RESPONSE)
local
f: RAW_FILE
do
if attached layout as lay then
create f.make (lay.callback_file_name)
if not f.exists or else f.is_writable then
f.open_write
res.send (f)
f.close
else
die (0)
end
else
die (0)
end
end
feature {NONE} -- Implementation
boolean_question (m: READABLE_STRING_8; a_options: detachable ITERABLE [TUPLE [key: READABLE_STRING_8; value: BOOLEAN]]; def: detachable STRING_8): BOOLEAN
local
s: STRING_8
l_answered: BOOLEAN
l_options: detachable ITERABLE [TUPLE [key: READABLE_STRING_8; value: BOOLEAN]]
do
from
until
l_answered
loop
io.put_string (m)
if l_options = Void then
l_options := a_options
end
if l_options = Void then
l_options := <<["y", True], ["Y", True]>>
end
io.read_line
s := io.last_string
s.left_adjust
s.right_adjust
if s.is_empty and def /= Void then
s := def
end
if not s.is_empty then
across
l_options as o
until
l_answered
loop
if o.item.key.same_string (s) then
l_answered := True
Result := o.item.value
end
end
if not l_answered then
l_answered := True
Result := False
end
end
end
end
string_question (m: READABLE_STRING_8; a_options: detachable ITERABLE [TUPLE [key: READABLE_STRING_8; value: detachable READABLE_STRING_8]]; def: detachable READABLE_STRING_8; a_required_valid_option: BOOLEAN): detachable READABLE_STRING_8
local
s: STRING_8
l_answered: BOOLEAN
do
from
until
l_answered
loop
io.put_string (m)
io.read_line
s := io.last_string
s.left_adjust
s.right_adjust
if s.is_empty and def /= Void then
s := def
end
if not s.is_empty then
if a_options /= Void then
across
a_options as o
until
l_answered
loop
if o.item.key.same_string (s) then
l_answered := True
Result := o.item.value
end
end
end
if not l_answered then
l_answered := True
Result := s
if
a_required_valid_option and then
a_options /= Void and then
not across a_options as o some attached o.item.value as v and then Result.same_string (v) end
then
l_answered := False
Result := Void
end
end
end
end
end
copy_file (a_src, a_target: READABLE_STRING_8)
local
f,t: RAW_FILE
do
create f.make (a_src)
if f.exists and f.is_readable then
create t.make (a_target)
if not t.exists or else t.is_writable then
f.open_read
t.open_write
f.copy_to (t)
t.close
f.close
end
end
end
new_uuid: STRING_8
local
gen: UUID_GENERATOR
do
create gen
Result := gen.generate_uuid.out
end
feature -- Resources
copy_resource (a_res: READABLE_STRING_8; a_target: READABLE_STRING_8)
do
if attached layout as lay then
copy_file (lay.resource (a_res), a_target)
end
end
copy_resource_template (a_res: READABLE_STRING_8; a_target: READABLE_STRING_8)
local
f,t: RAW_FILE
do
if attached layout as lay then
create f.make (lay.resource (a_res))
if f.exists and f.is_readable then
create t.make (a_target)
if not t.exists or else t.is_writable then
f.open_read
t.create_read_write
from
f.read_line
until
f.exhausted
loop
across
variables as v
loop
f.last_string.replace_substring_all ("${WIZ:" + v.key + "}", v.item)
end
t.put_string (f.last_string)
t.put_new_line
f.read_line
end
t.close
f.close
end
end
end
end
end

View File

@@ -0,0 +1,20 @@
note
description: "Summary description for {WIZARD_FAILED_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WIZARD_FAILED_RESPONSE
inherit
WIZARD_RESPONSE
feature -- Output
send (f: FILE)
do
f.put_string ("Success=%"no%"%N")
end
end

View File

@@ -0,0 +1,49 @@
note
description: "Summary description for {WIZARD_LAYOUT}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WIZARD_LAYOUT
create
make
feature {NONE} -- Initialization
make (d: like wizard_directory_name; cb: like callback_file_name)
do
wizard_directory_name := d
callback_file_name := cb
end
feature -- Access
wizard_directory_name: READABLE_STRING_8
resource (a_name: READABLE_STRING_8): STRING_8
local
fn: FILE_NAME
do
create fn.make_from_string (wizard_directory_name)
fn.extend ("resources")
fn.set_file_name (a_name)
Result := fn.string
end
pixmap_png_filename (a_name: READABLE_STRING_8): STRING_8
local
fn: FILE_NAME
do
create fn.make_from_string (wizard_directory_name)
fn.extend ("pixmaps")
fn.set_file_name (a_name)
fn.add_extension ("png")
Result := fn.string
end
callback_file_name: READABLE_STRING_8
invariant
end

View File

@@ -0,0 +1,16 @@
note
description: "Summary description for {WIZARD_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
deferred class
WIZARD_RESPONSE
feature -- Output
send (f: FILE)
deferred
end
end

View File

@@ -0,0 +1,68 @@
note
description: "Summary description for {WIZARD_SUCCEED_RESPONSE}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
WIZARD_SUCCEED_RESPONSE
inherit
WIZARD_RESPONSE
create
make
feature {NONE} -- Initialization
make (a_conf_fn: like configuration_file_name; a_dir: like directory_name)
do
configuration_file_name := a_conf_fn
directory_name := a_dir
end
feature -- Access
configuration_file_name: READABLE_STRING_8
directory_name: READABLE_STRING_8
compile_enabled: BOOLEAN
freeze_required: BOOLEAN
feature -- Element Change
set_compile_enabled (b: BOOLEAN)
do
compile_enabled := b
end
set_freeze_required (b: BOOLEAN)
do
freeze_required := b
end
feature -- Constants
melt_compilation: INTEGER = 0
freeze_compilation: INTEGER = 1
feature -- Output
send (f: FILE)
do
f.put_string ("Success=%"yes%"%N")
f.put_string ("Ace=%"" + configuration_file_name + "%"%N")
f.put_string ("Directory=%"" + directory_name + "%"%N")
if compile_enabled then
f.put_string ("Compilation=%"yes%"%N")
else
f.put_string ("Compilation=%"no%"%N")
end
if freeze_required then
f.put_string ("Compilation_type=%"freeze%"%N")
elseif compile_enabled then
f.put_string ("Compilation_type=%"melt%"%N")
end
end
end