patch to Yapp for starting dependencies
I recently upgraded to yaws 1.65. I was excited to discover the yapp
module. What a great idea! Now I'm writing a yapp that uses the
crypto application. Since yapps are supposed to be proper OTP
applications, I delcare the dependency on crypto in anshoref.app:
{application, anshoref,
[{description, "Ansho Reference Application"}
,{vsn, "0.1"}
,{modules, [anshoref]}
,{applications, [kernel, stdlib, mnesia, crypto]}
,{mod, {anshoref, []}}
]}.
The problem is that Yapp doesn't start crypto before starting my yapp.
The following patch changes the way that Yapp starts applications.
The old code is complicated, duplicating many functions of
application:start/1. My patch simplifies the procedure by relying on
application:start/1 to load, start, and return meaningful error
messages. The new start_app/1 function recursively loads all
application dependencies.
Here is the patch. I hope I created it correctly and gmail doesn't mangle it.
-Michael
michael206@...
http://tamale.net/
yaws-1.65/applications/yapp/src$ diff -Nurp yapp.erl-before yapp.erl
--- yapp.erl-before 2006-09-09 13:40:21.000000000 -0400
+++ yapp.erl 2006-10-08 15:28:15.000000000 -0400
<at> <at> -219,29 +219,31 <at> <at> insert_yapp_in_sconfgroup(SrvId, Yapp, [
%% the yapp application itself maybe a yapp, treated as special case
insert_yapp_in_sconf({UrlPath, yapp}, SC) ->
- insert_yapp_in_sconf1({UrlPath, yapp}, SC);
+ insert_yapp_in_sconf0({UrlPath, yapp}, SC);
insert_yapp_in_sconf({UrlPath, AppName}, SC) ->
- case application:load(AppName) of
+ case start_app([AppName]) of
ok ->
insert_yapp_in_sconf0({UrlPath, AppName}, SC);
- {error,{already_loaded,AppName}} ->
- insert_yapp_in_sconf0({UrlPath, AppName}, SC);
Error ->
- log(error, "yapp:insert_yapp_in_sconf - Yapp not found ~p,
~p", [AppName, Error]),
+ log(error, "yapp:insert_yapp_in_sconf - Error loading Yapp
~p, ~p", [AppName, Error]),
no_app
end.
-insert_yapp_in_sconf0({UrlPath, AppName}, SC) ->
- case lists:keymember(AppName, 1, application:which_applications()) of
- false ->
- log(info, "Starting app ~p" , [AppName]),
- application:start(AppName);
- _ ->
- do_nothing
- end,
- insert_yapp_in_sconf1({UrlPath, AppName}, SC).
+start_app([AppName|T]) ->
+ log(info, "Starting app ~p" , [AppName]),
+ case application:start(AppName) of
+ {error,{not_started,RequiredApp}} ->
+ start_app([RequiredApp,AppName|T]);
+ {error,{already_started,AppName}} ->
+ start_app(T);
+ ok ->
+ start_app(T);
+ Error -> Error
+ end;
+start_app([]) -> ok;
+start_app(Error) -> Error.
-insert_yapp_in_sconf1({UrlPath, AppName}, #sconf{opaque = OP} = SC) ->
+insert_yapp_in_sconf0({UrlPath, AppName}, #sconf{opaque = OP} = SC) ->
log(info,"Inserting App ~p in Url ~p~n", [AppName, UrlPath]),
AppEnv = application:get_all_env(AppName),
DocSubRoot = proplists:get_value(yapp_docroot,AppEnv, ?priv_docroot),
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV