Merge branch 'ewf_v1_roctool' into ewf_v1

This commit is contained in:
2015-06-29 17:30:39 +02:00
56 changed files with 870 additions and 24 deletions

View File

@@ -27,12 +27,15 @@ feature {NONE} -- Initialization
make
do
name := "Blog demo module"
version := "1.0"
description := "Service to demonstrate new node for blog"
package := "demo"
end
feature -- Access
name: STRING = "blog"
feature {CMS_API} -- Module Initialization
initialize (api: CMS_API)

View File

@@ -27,12 +27,15 @@ feature {NONE} -- Initialization
make
do
name := "Demo module"
version := "1.0"
description := "Service to demonstrate and test cms system"
package := "demo"
end
feature -- Access
name: STRING = "demo"
feature {CMS_API} -- Module Initialization
initialize (api: CMS_API)

3
license.lic Normal file
View File

@@ -0,0 +1,3 @@
${NOTE_KEYWORD}
copyright: "2011-${YEAR}, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -10,10 +10,10 @@
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="standard">
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="$ISE_LIBRARY\unstable\library\web\cms\cms-safe.ecf" readonly="false"/>
<library name="cms_app_env" location="$ISE_LIBRARY\unstable\library\web\cms\library\app_env\app_env-safe.ecf" readonly="false"/>
<library name="cms_model" location="$ISE_LIBRARY\unstable\library\web\cms\library\model\cms_model-safe.ecf" readonly="false"/>
<library name="config" location="$ISE_LIBRARY\unstable\library\web\cms\library\configuration\config-safe.ecf"/>
<library name="cms" location="..\..\cms-safe.ecf" readonly="false"/>
<library name="cms_app_env" location="..\..\library\app_env\app_env-safe.ecf" readonly="false"/>
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
<library name="config" location="..\..\library\configuration\config-safe.ecf"/>
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
<library name="http" location="$ISE_LIBRARY\contrib\library\network\protocol\http\http-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>

View File

@@ -31,7 +31,7 @@ feature {NONE} -- Initialization
admin_email := l_site_name + " <" + admin_email +">"
end
if attached {CONFIG_READER} a_cms_api.module_configuration_by_name ("login", Void) as cfg then
if attached {CONFIG_READER} a_cms_api.module_configuration_by_name ({CMS_AUTHENTICATION_MODULE}.name, Void) as cfg then
if attached cfg.text_item ("smtp") as l_smtp then
-- Overwrite global smtp setting if any.
smtp_server := utf.utf_32_string_to_utf_8_string_8 (l_smtp)
@@ -138,7 +138,7 @@ feature {NONE} -- Implementation: Template
p: PATH
do
create p.make_from_string (a_name)
Result := cms_api.module_location_by_name ("login").extended ("mail_templates").extended (a_name)
Result := cms_api.module_location_by_name ({CMS_AUTHENTICATION_MODULE}.name).extended ("mail_templates").extended (a_name)
end
template_string (a_name: READABLE_STRING_GENERAL; a_default: STRING): STRING

View File

@@ -8,12 +8,10 @@ class
inherit
CMS_MODULE
redefine
register_hooks
end
CMS_HOOK_BLOCK
CMS_HOOK_AUTO_REGISTER
@@ -33,7 +31,6 @@ inherit
CMS_REQUEST_UTIL
create
make
@@ -42,7 +39,6 @@ feature {NONE} -- Initialization
make
-- Create current module
do
name := "login"
version := "1.0"
description := "Authentication module"
package := "authentication"
@@ -51,6 +47,10 @@ feature {NONE} -- Initialization
cache_duration := 0
end
feature -- Access
name: STRING = "auth"
feature -- Access: docs
root_dir: PATH

View File

@@ -0,0 +1,8 @@
{
"email": "webmaster@example.com",
"subjet_register": "Thank you for regitering with us, activate account",
"subjet_activate": "New account ativation token",
"subjet_password": "Password Recovery!!!",
"subjet_oauth": "Welcome",
"smtp": "127.0.0.1"
}

View File

@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Activation</title>
<meta name="description" content="Activation">
<meta name="author" content="ROC CMS">
</head>
<body>
<p>Thank you for registering at <a href="$host">ROC CMS</a></p>
<p>To complete your registration, please click on this link to activate your account:<p>
<p><a href="$link">$link</a></p>
<p>Thank you for joining us.</p>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>New Password</title>
<meta name="description" content="New Password">
<meta name="author" content="ROC CMS">
</head>
<body>
<p>You have required a new password at <a href="...">ROC CMS</a></p>
<p>To complete your request, please click on this link to genereate a new password:<p>
<p><a href="$link">$link</a></p>
</body>
</html>

View File

@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>New Activation</title>
<meta name="description" content="New Activation token">
<meta name="author" content="ROC CMS">
</head>
<body>
<p>You have request a new activation token at<a href="...">ROC CMS</a></p>
<p>To complete your registration, please click on this link to activate your account:<p>
<p><a href="$link">$link</a></p>
<p>Thank you for joining us.</p>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome</title>
<meta name="description" content="Welcome">
<meta name="author" content="ROC CMS">
</head>
<body>
<p>Welcome to<a href="...">ROC CMS</a></p>
<p>Thank you for joining us.</p>
</body>
</html>

View File

@@ -0,0 +1,7 @@
{
"api_secret":"ADD_YOUR_SECRET_KEY",
"api_key":"ADD_YOUR_PUBLIC_KEY",
"scope": "email",
"api_revoke":"https://accounts.google.com/o/oauth2/revoke?token=$ACCESS_TOKEN",
"protected_resource_url":"https://www.googleapis.com/plus/v1/people/me"
}

View File

@@ -0,0 +1,34 @@
<div class="primary-tabs">
{unless isset="$user"}
<h3>Login or <a href="{$site_url/}account/roc-register">Register</a></h3>
<div>
<div>
<form action method="POST">
<div>
<input type="text" name="username" required>
<label>Username</label>
</div>
<div>
<input type="password" name="password" required>
<label>Password</label>
</div>
<button type="button" onclick="ROC_AUTH.login();">Login</button>
</form>
</div>
</div>
<div>
<div>
<p>
<a href="{$site_url/}account/new-password">Forgot password?</a>
</p>
</div>
</div>
<div>
{foreach item="item" from="$oauth_consumers"}
<a href="{$site_url/}account/login-with-oauth/{$item/}">Login with {$item/}</a><br>
{/foreach}
</div>
{/unless}
</div>

View File

@@ -0,0 +1,16 @@
<div>
<form action="/account/new-password" method="post">
<fieldset>
<legend>Require new password</legend>
<div>
<input type="email" id="email" name="email" value="{$email/}" required/>
<label for="email">Email</label>
{if isset="$error_email"}
<span><i>{$error_email/}</i></span> <br>
{/if}
<br>
</div>
<button type="submit">Send</button>
</fieldset>
</form>
</div>

View File

@@ -0,0 +1,3 @@
<div>
<p>We have send you a new token code, check your email to generate a new password</p>
</div>

View File

@@ -0,0 +1,3 @@
<div>
<p>We have send you a new activation code, check your email to activate your account.</p>
</div>

View File

@@ -0,0 +1,3 @@
<div>
<p>Thanks for register, check your email to activate your account.</p>
</div>

View File

@@ -0,0 +1,3 @@
<div>
<p>You new password has been saved!</p>
</div>

View File

@@ -0,0 +1,19 @@
<div>
<form action="/account/reactivate" method="post">
<fieldset>
<legend>Reactivate Form</legend>
<div>
<input type="email" id="email" name="email" value="{$email/}" required/>
<label for="email">Email</label>
{if isset="$error_email"}
<span><i>{$error_email/}</i></span> <br>
{/if}
<br>
{if isset="$is_active"}
<span><i>{$is_active/}</i></span> <br>
{/if}
</div>
<button type="submit">Reactivate</button>
</fieldset>
</form>
</div>

View File

@@ -0,0 +1,28 @@
<div>
<form action="/account/roc-register" method="post">
<fieldset>
<legend>Register Form</legend>
<div>
<input type="text" id="name" name="name" value="{$name/}" required autofocus />
<label for="name">Name</label>
{if isset="$error_name"}
<span><i>{$error_name/}</i></span> <br>
{/if}
</div>
<div>
<input type="password" id="password" name="password" value="" required/>
<label for="password">Password</label>
</div>
<div>
<input type="email" id="email" name="email" value="{$email/}" required/>
<label for="email">Email</label>
{if isset="$error_email"}
<span><i>{$error_email/}</i></span> <br>
{/if}
</div>
<button type="submit">Register</button>
</fieldset>
</form>
</div>

View File

@@ -0,0 +1,28 @@
<div>
<form action="/account/reset-password" method="post">
<fieldset>
<legend>Generate New Password Form</legend>
<div>
<input type="text" id="token" name="token" value="{$token/}" required />
<label for="token">Token</label>
{if isset="$error_token"}
<span><i>{$error_token/}</i></span> <br>
{/if}
</div>
<div>
<input type="password" id="password" name="password" value="" required/>
<label for="password">Password</label>
</div>
<div>
<input type="password" id="confirm_password" name="confirm_password" value="" required/>
<label for="password">Confirm Password</label>
</div>
<button type="submit">Confirm</button>
{if isset="$error_password"}
<span><i>{$error_password/}</i></span> <br>
{/if}
</fieldset>
</form>
</div>

View File

@@ -29,12 +29,15 @@ feature {NONE} -- Initialization
make
do
name := "basic auth"
version := "1.0"
description := "Service to manage basic authentication"
package := "core"
end
feature -- Access
name: STRING = "basic_auth"
feature -- Access: router
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)

View File

@@ -29,7 +29,6 @@ feature {NONE} -- Initialization
make (a_setup: CMS_SETUP)
-- Create Current module, disabled by default.
do
name := "node"
version := "1.0"
description := "Service to manage content based on 'node'"
package := "core"
@@ -39,6 +38,10 @@ feature {NONE} -- Initialization
config: CMS_SETUP
-- Node configuration.
feature -- Access
name: STRING = "node"
feature {CMS_API} -- Module Initialization
initialize (a_api: CMS_API)

View File

@@ -0,0 +1,22 @@
CREATE TABLE nodes (
`nid` INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT UNIQUE,
`revision` INTEGER,
`type` TEXT NOT NULL,
`title` VARCHAR(255) NOT NULL,
`summary` TEXT,
`content` TEXT,
`format` VARCHAR(128),
`author` INTEGER,
`publish` DATETIME,
`created` DATETIME NOT NULL,
`changed` DATETIME NOT NULL,
`status` INTEGER
);
CREATE TABLE page_nodes(
`nid` INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
`revision` INTEGER,
`parent` INTEGER
);

View File

@@ -21,7 +21,7 @@ feature {NONE} -- Initialization
s: detachable READABLE_STRING_32
l_contact_email, l_subject_register, l_subject_activate, l_subject_password, l_subject_oauth: detachable READABLE_STRING_8
do
setup := a_cms_api.setup
cms_api := a_cms_api
-- Use global smtp setting if any, otherwise "localhost"
smtp_server := utf.escaped_utf_32_string_to_utf_8_string_8 (a_cms_api.setup.text_item_or_default ("smtp", "localhost"))
l_site_name := utf.escaped_utf_32_string_to_utf_8_string_8 (a_cms_api.setup.site_name)
@@ -31,7 +31,7 @@ feature {NONE} -- Initialization
admin_email := l_site_name + " <" + admin_email +">"
end
if attached {CONFIG_READER} a_cms_api.module_configuration_by_name ("login", Void) as cfg then
if attached {CONFIG_READER} a_cms_api.module_configuration_by_name ({CMS_AUTHENTICATION_MODULE}.name, Void) as cfg then
if attached cfg.text_item ("smtp") as l_smtp then
-- Overwrite global smtp setting if any.
smtp_server := utf.utf_32_string_to_utf_8_string_8 (l_smtp)
@@ -133,7 +133,7 @@ feature {NONE} -- Implementation: Template
template_path (a_name: READABLE_STRING_GENERAL): PATH
-- Location of template named `a_name'.
do
Result := setup.environment.config_path.extended ("modules").extended ("login").extended (a_name)
Result := cms_api.module_location_by_name ({CMS_AUTHENTICATION_MODULE}.name).extended (a_name)
end
template_string (a_name: READABLE_STRING_GENERAL; a_default: STRING): STRING
@@ -151,7 +151,7 @@ feature {NONE} -- Implementation: Template
feature {NONE} -- Implementation
setup: CMS_SETUP
cms_api: CMS_API
read_template_file (a_path: PATH): detachable STRING
-- Read the content of the file at path `a_path'.

View File

@@ -47,7 +47,6 @@ feature {NONE} -- Initialization
make
-- Create current module
do
name := "oauth20"
version := "1.0"
description := "OAuth20 module"
package := "Oauth20"
@@ -56,6 +55,10 @@ feature {NONE} -- Initialization
cache_duration := 0
end
feature -- Access
name: STRING = "oauth20"
feature {CMS_API} -- Module Initialization
initialize (a_api: CMS_API)

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="oauth_module" uuid="D64B990F-B51F-4E0D-AB2E-4AA5DDB783CE" library_target="oauth_module">
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-14-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-14-0 http://www.eiffel.com/developers/xml/configuration-1-14-0.xsd" name="oauth_module" uuid="D64B990F-B51F-4E0D-AB2E-4AA5DDB783CE" library_target="oauth_module">
<target name="oauth_module">
<root all_classes="true"/>
<file_rule>
@@ -12,6 +12,7 @@
<library name="apis" location="$ISE_LIBRARY\contrib\library\web\authentication\oauth\cypress\consumer\apis\apis.ecf" readonly="false"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="$ISE_LIBRARY\unstable\library\web\cms\cms-safe.ecf" readonly="false"/>
<library name="cms_auth_module" location="..\auth\auth-safe.ecf" readonly="false"/>
<library name="cms_app_env" location="$ISE_LIBRARY\unstable\library\web\cms\library\app_env\app_env-safe.ecf" readonly="false"/>
<library name="cms_model" location="$ISE_LIBRARY\unstable\library\web\cms\library\model\cms_model-safe.ecf" readonly="false"/>
<library name="config" location="$ISE_LIBRARY\unstable\library\web\cms\library\configuration\config-safe.ecf"/>

View File

@@ -0,0 +1,18 @@
CREATE TABLE oauth2_consumers(
`cid` INTEGER PRIMARY KEY NOT NULL CHECK(`cid`>=0),
`name` VARCHAR(255) NOT NULL,
`api_secret` TEXT NOT NULL,
`api_key` TEXT NOT NULL,
`scope` VARCHAR (100) NOT NULL,
`protected_resource_url` VARCHAR (255) NOT NULL,
`callback_name` VARCHAR(255) NOT NULL,
`extractor` VARCHAR(50) NOT NULL,
`authorize_url` VARCHAR (255) NOT NULL,
`endpoint` VARCHAR (255) NOT NULL,
CONSTRAINT `cid`
UNIQUE(`cid`),
CONSTRAINT `name`
UNIQUE(`name`)
);

View File

@@ -0,0 +1,7 @@
-- Change the values TO_COMPLETE based on your API.
-- API SECTET KEY AND API PUBLIC KEY
INSERT INTO oauth2_consumers (name, api_secret, api_key, scope, protected_resource_url, callback_name, extractor, authorize_url, endpoint)
VALUES ('google', 'TO-COMPLETE', 'TO-COMPLETE', 'email', 'https://www.googleapis.com/plus/v1/people/me', 'callback_google', 'json','https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=$CLIENT_ID&redirect_uri=$REDIRECT_URI','https://accounts.google.com/o/oauth2/token');
INSERT INTO oauth2_consumers (name, api_secret, api_key, scope, protected_resource_url, callback_name, extractor, authorize_url, endpoint )
VALUES ('facebook', 'TO-COMPLETE', 'TO-COMPLETE', 'email', 'https://graph.facebook.com/me', 'callback_facebook','text','https://www.facebook.com/dialog/oauth?response_type=code&client_id=$CLIENT_ID&redirect_uri=$REDIRECT_URI','https://graph.facebook.com/oauth/access_token');

View File

@@ -0,0 +1,10 @@
CREATE TABLE $table_name (
`uid` INTEGER PRIMARY KEY NOT NULL CHECK(`uid`>=0),
`access_token` TEXT NOT NULL,
`created` DATETIME NOT NULL,
`details` TEXT NOT NULL,
CONSTRAINT `uid`
UNIQUE(`uid`)
);

View File

@@ -0,0 +1,7 @@
<div class="primary-tabs">
<div>
{foreach item="item" from="$oauth_consumers"}
<a href="{$site_url/}account/login-with-oauth/{$item/}">Login with {$item/}</a><br>
{/foreach}
</div>
</div>

View File

@@ -42,6 +42,8 @@ feature {NONE} -- Initialization
local
l_url: like site_url
do
site_location := environment.path
--| Site id, used to identified a site, this could be set to a uuid, or else
site_id := text_item_or_default ("site.id", "_EWF_CMS_NO_ID_")
@@ -169,4 +171,7 @@ feature -- Theme: Compute location
theme_location := themes_location.extended (theme_name)
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -92,6 +92,9 @@ feature -- Query
feature -- Access: Theme
site_location: PATH
-- Path to CMS site root dir.
modules_location: PATH
-- Path to modules.
@@ -186,4 +189,7 @@ feature -- Element change
module_registered: module_registered (m)
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -28,12 +28,15 @@ feature {NONE} -- Initialization
make
do
name := "debug"
version := "1.0"
description := "Debug"
package := "cms"
end
feature -- Access
name: STRING = "debug"
feature -- Router
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
@@ -134,7 +137,7 @@ feature -- Handler
end
note
copyright: "Copyright (c) 1984-2013, Eiffel Software and others"
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -319,6 +319,12 @@ feature {NONE}-- Implemenation
feature -- Environment/ theme
site_location: PATH
-- CMS site location.
do
Result := setup.site_location
end
theme_location: PATH
-- Active theme location.
do
@@ -349,6 +355,7 @@ feature -- Environment/ module
else
l_name := a_name
end
p := setup.environment.config_path
p := module_location_by_name (a_module_name).extended ("config").extended (l_name)
@@ -393,7 +400,14 @@ feature -- Environment/ module
-- Location of resource `a_resource' for `a_module'.
do
--| site/modules/$modname/$a_name.json
Result := module_location (a_module).extended_path (a_resource)
Result := module_resource_location_by_name (a_module.name, a_resource)
end
module_resource_location_by_name (a_module_name: READABLE_STRING_GENERAL; a_resource: PATH): PATH
-- Location of resource `a_resource' for `a_module'.
do
--| site/modules/$modname/$a_name.json
Result := module_location_by_name (a_module_name).extended_path (a_resource)
end
feature -- Environment/ modules and theme
@@ -419,10 +433,37 @@ feature -- Environment/ modules and theme
end
end
module_theme_resource_location_by_name (a_module_name: READABLE_STRING_GENERAL; a_resource: PATH): detachable PATH
-- Theme resource location of `a_resource' for module named `a_module_name', if exists.
-- By default, located under the module location folder, but could be overriden
-- from files located under modules subfolder of active `theme_location'.
--| First search in themes/$theme/modules/$a_module.name/$a_resource,
--| and if not found then search in
--| modules/$a_module_name/$a_resource.
local
ut: FILE_UTILITIES
do
-- Check first in selected theme folder.
Result := module_theme_location_by_name (a_module_name).extended_path (a_resource)
if not ut.file_path_exists (Result) then
-- And if not found, look into site/modules/$a_module.name/.... folders.
Result := module_resource_location_by_name (a_module_name, a_resource)
if not ut.file_path_exists (Result) then
Result := Void
end
end
end
module_theme_location (a_module: CMS_MODULE): PATH
-- Location for overriden files associated with `a_module_name'.
do
Result := theme_location.extended ("modules").extended (a_module.name)
Result := module_theme_location_by_name (a_module.name)
end
module_theme_location_by_name (a_module_name: READABLE_STRING_GENERAL): PATH
-- Location for overriden files associated with `a_module_name'.
do
Result := theme_location.extended ("modules").extended (a_module_name)
end
module_configuration (a_module: CMS_MODULE; a_name: detachable READABLE_STRING_GENERAL): detachable CONFIG_READER
@@ -430,5 +471,8 @@ feature -- Environment/ modules and theme
Result := module_configuration_by_name (a_module.name, a_name)
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -16,6 +16,8 @@ feature -- Access
name: STRING
-- Name of the module.
deferred
end
description: STRING
-- Description of the module.
@@ -132,4 +134,7 @@ feature -- Hooks
create Result.make_empty
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

122
tools/roc/application.e Normal file
View File

@@ -0,0 +1,122 @@
note
description: "[
roc tool: install modules into an existing CMS Application.
roc install [--module|-m <MODULE_PATH>] [(--dir|-d <CMS_PATH>) | <MODULE_NAME>]
install: Install a given module to the corresponding cms application
--module|-m: module path or current directory if is not defined.
--dir|-d cms application path or current directory if is not defined
Running the command will copy to the CMS Application site/modules the following artifacts if the current module provide them.
config
scripts
themes
running
roc install blog
will look for a module blog in the modules directory starting at the current directory.
]"
date: "$Date$"
revision: "$Revision$"
class
APPLICATION
inherit
SHARED_EXECUTION_ENVIRONMENT
rename
print as ascii_print
end
ARGUMENTS_32
rename
print as ascii_print
end
LOCALIZED_PRINTER
rename
print as ascii_print,
localized_print as print
end
create
make
feature {NONE} -- Initialization
make
-- Initialize tool.
local
cmd_args: like command_arguments
do
-- TODO add support to other commands.
if argument_count = 0 then
print_usage
elseif attached commands.item (argument (1)) as cmd then
cmd_args := command_arguments
if cmd.is_valid (cmd_args) then
cmd.execute (cmd_args)
else
print_command_usage (cmd)
end
else
print ("Wrong command %"" + argument (1) + "%".%N")
print_usage
end
end
commands: STRING_TABLE [ROC_COMMAND]
local
cmd: ROC_COMMAND
once
create Result.make (1)
create {ROC_INSTALL_COMMAND} cmd.make ("install")
Result.force (cmd, cmd.name)
end
command_arguments: ARRAY [READABLE_STRING_32]
local
i,n: INTEGER
do
create Result.make_empty
Result.rebase (0)
Result.force (argument (0), 0)
from
i := 2 -- skip first arg which is command name
n := argument_count
until
i > n
loop
Result.force (argument (i), i - 1)
i := i + 1
end
end
feature -- Usage
print_usage
do
print ("Usage:%N")
across
commands as ic
loop
print_command_usage (ic.item)
end
end
print_command_usage (cmd: ROC_COMMAND)
do
print ("roc ")
print (cmd.name)
print (" ")
print (cmd.help)
print ("%N")
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

3
tools/roc/license.lic Normal file
View File

@@ -0,0 +1,3 @@
${NOTE_KEYWORD}
copyright: "2011-${YEAR}, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

19
tools/roc/roc.ecf Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-14-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-14-0 http://www.eiffel.com/developers/xml/configuration-1-14-0.xsd" name="roc" uuid="10B0F9A7-B711-419B-A1B5-833EB61DF8A6">
<target name="roc">
<root class="APPLICATION" feature="make"/>
<option warning="true" void_safety="all">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="encoding" location="$ISE_LIBRARY\library\encoding\encoding-safe.ecf"/>
<cluster name="roc" location=".\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
</cluster>
</target>
</system>

53
tools/roc/roc_command.e Normal file
View File

@@ -0,0 +1,53 @@
note
description: "Abstraction of roc command."
date: "$Date$"
revision: "$Revision$"
deferred class
ROC_COMMAND
inherit
SHARED_EXECUTION_ENVIRONMENT
rename
print as ascii_print
end
LOCALIZED_PRINTER
rename
print as ascii_print,
localized_print as print
end
feature {NONE} -- Initialization
make (a_name: READABLE_STRING_8)
do
create name.make_from_string (a_name)
end
feature -- Access
name: IMMUTABLE_STRING_8
help: STRING_32
deferred
end
feature -- Status report
is_valid (args: ARRAY [READABLE_STRING_32]): BOOLEAN
deferred
end
feature -- Execution
execute (args: ARRAY [READABLE_STRING_32])
require
args.lower = 0 -- Prog name at index 0, args at index 1, ...
deferred
end
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end

View File

@@ -0,0 +1,285 @@
note
description: "Installation command."
date: "$Date$"
revision: "$Revision$"
class
ROC_INSTALL_COMMAND
inherit
ROC_COMMAND
create
make
feature -- Access
help: STRING_32
once
Result := "[--module|-m <MODULE_PATH>] [(--dir|-d <CMS_PATH>) | <MODULE_NAME>] [--site-dir <CMS_SITE_PATH>]"
end
feature -- Status report
is_valid (args: ARRAY [READABLE_STRING_32]): BOOLEAN
-- Is the submitted install command valid?
local
i, n: INTEGER
optional_module: BOOLEAN
cms_path: BOOLEAN
do
n := args.upper
-- TODO add error reporting.
if n >= 1 and then n <= 4 then
from
i := 1
until
i > n
loop
if args [i].same_string ("-m") then
optional_module := True
elseif args [i].same_string ("--module") then
optional_module := True
elseif args [i].same_string ("-d") then
cms_path := True
elseif args [i].same_string ("--dir") then
cms_path := True
end
i := i + 1
end
if n = 4 then
if (cms_path and optional_module) then
-- valid command
Result := True
else
print ("Error check the optional argument --module|-m and --dir|-d")
end
elseif n = 2 then
if (cms_path and not optional_module) then
Result := True
else
print ("Error missing value for dir")
Result := False
end
else
Result := True
end
else
Result := False
if n > 4 then
print ("Too many arguments")
end
if n < 1 then
print ("Too few argumetns")
end
end
end
feature -- Helpers
module_name (a_path: PATH): STRING_32
do
-- FIXME: better implementation needed. Either based on "a" new module.info file, or parsing the .ecf
if attached a_path.entry as e then
Result := e.name
else
Result := a_path.name
end
end
feature -- Execution
execute (args: ARRAY [READABLE_STRING_32])
-- Install a module into a cms application.
-- Pattern: module_src/site/* => cms/site/modules/$module_name/*
local
l_site_path, l_cms_path, l_module_source_path: detachable PATH
l_site_dir: DIRECTORY
l_modules_dir: DIRECTORY
l_dest_dir: DIRECTORY
i,n: INTEGER
do
from
i := 1
n := args.upper
until
i > n
loop
if attached args[i] as arg then
if
arg.same_string ("-d")
or arg.same_string ("--dir")
then
i := i + 1
if i <= n then
create l_cms_path.make_from_string (args[i])
end
elseif
arg.same_string ("--site-dir")
then
i := i + 1
if i <= n then
create l_site_path.make_from_string (args[i])
end
elseif
arg.same_string ("-m")
or arg.same_string ("--module")
then
i := i + 1
if i <= n then
create l_module_source_path.make_from_string (args[i])
end
end
end
i := i + 1
end
if l_module_source_path = Void then
l_module_source_path := Execution_environment.current_working_path
end
if l_cms_path = Void then
l_cms_path := Execution_environment.current_working_path.extended ("modules")
end
if l_cms_path /= Void and l_module_source_path /= Void then
-- If l_site_path is not set; initialize it to $cms_path/site.
if l_site_path = Void then
l_site_path := l_cms_path.extended ("site")
end
-- Install configuration files.
if attached module_name (l_module_source_path) as l_mod_name then
create l_site_dir.make_with_path (l_site_path)
if l_site_dir.exists then
create l_modules_dir.make_with_path (l_site_path.extended ("modules"))
if not l_modules_dir.exists then
l_modules_dir.create_dir
end
create l_dest_dir.make_with_path (l_modules_dir.path.extended (l_mod_name))
if not l_dest_dir.exists then
l_dest_dir.create_dir
end
install_module_elements (l_module_source_path, l_dest_dir.path, Void)
-- install_module_elements (l_module_source_path, l_dest_dir.path, Config_dir)
-- install_module_elements (l_module_source_path, l_dest_dir.path, Scripts_dir)
-- install_module_elements (l_module_source_path, l_dest_dir.path, Themes_dir)
print ("Module ")
print (l_mod_name)
print (" was successfuly installed to the CMS Application location ")
print (l_cms_path.name)
print ("%NCheck the module elements at ")
print (l_dest_dir.path.name)
print (".%N")
else
print ({STRING_32} "The CMS Application located at " + l_cms_path.name + "does not have the site or modules folders.%N")
end
else
print ("Error: not possible to retrieve module name.%N")
end
else
print ("Error: wrong path to CMS application.%N")
end
end
install_module_elements (a_module_source_path: PATH; a_cms_module_target_path: PATH; a_element: detachable READABLE_STRING_GENERAL)
-- Install module site files from `a_module_source_path' to cms application `a_cms_module_target_path' under expected modules folder.
-- If `a_element' is set, take into account only sub folder `a_element'.
local
l_path: PATH
l_dest_dir: DIRECTORY
l_src_dir: DIRECTORY
do
l_path := a_module_source_path.extended ("site")
if a_element /= Void then
-- Copy all files under "site/$a_element" into "site/modules/$module_name/$a_element" location.
create l_src_dir.make_with_path (l_path.extended (a_element))
create l_dest_dir.make_with_path (a_cms_module_target_path.extended (a_element))
else
-- Copy all files under "site" into "site/modules/$module_name/" location.
create l_src_dir.make_with_path (l_path)
create l_dest_dir.make_with_path (a_cms_module_target_path)
end
if not l_dest_dir.exists then
l_dest_dir.create_dir
end
copy_directory (l_src_dir, l_dest_dir, True)
end
feature {NONE} -- System/copy files
copy_directory (a_src: DIRECTORY; a_dest: DIRECTORY; is_recursive: BOOLEAN)
-- Copy all elements from `a_src' to `a_dest'.
local
l_dir: DIRECTORY
l_new_dir: DIRECTORY
entry: PATH
l_path: PATH
l_file: FILE
ut: FILE_UTILITIES
do
across
a_src.entries as ic
loop
entry := ic.item
if not (entry.is_current_symbol or else entry.is_parent_symbol) then
l_path := a_src.path.extended_path (entry)
create {RAW_FILE} l_file.make_with_path (l_path)
if not l_file.is_directory then
copy_file_in_directory (l_file, a_dest.path)
elseif is_recursive then
create l_dir.make_with_path (l_path)
create l_new_dir.make_with_path (a_dest.path.extended_path (entry))
ut.create_directory_path (l_new_dir.path)
if l_dir.exists then
copy_directory (l_dir, l_new_dir, is_recursive)
end
end
end
end
end
copy_file_in_directory (a_file: FILE; a_dir: PATH)
-- Copy file `a_file' to dir `a_dir'.
local
retried: BOOLEAN
l_dest: RAW_FILE
do
if not retried then
if attached a_file.path.entry as e then
create l_dest.make_with_path (a_dir.extended_path (e))
l_dest.create_read_write
a_file.open_read
-- Copy file source to destination
if
l_dest.exists and then
l_dest.is_writable and then
a_file.exists and then
a_file.is_readable
then
a_file.copy_to (l_dest)
a_file.close
l_dest.close
end
end
end
rescue
retried := True
retry
end
--feature -- Constants
-- Config_dir: STRING = "config"
-- -- Configuration dir.
-- Scripts_dir: STRING = "scripts"
-- -- Scripts dir.
-- Themes_dir: STRING = "themes"
-- -- Themes dir.
note
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
end