diff options
Diffstat (limited to 'deps/mochiweb/priv/skel')
-rw-r--r-- | deps/mochiweb/priv/skel/Makefile | 20 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/priv/www/index.html | 8 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/src/Makefile | 33 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/src/skel.app | 14 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/src/skel.erl | 30 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/src/skel.hrl | 1 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/src/skel_app.erl | 30 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/src/skel_deps.erl | 92 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/src/skel_sup.erl | 62 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/src/skel_web.erl | 51 | ||||
-rwxr-xr-x | deps/mochiweb/priv/skel/start-dev.sh | 12 | ||||
-rwxr-xr-x | deps/mochiweb/priv/skel/start.sh | 3 | ||||
-rw-r--r-- | deps/mochiweb/priv/skel/support/include.mk | 40 | ||||
-rwxr-xr-x | deps/mochiweb/priv/skel/support/run_tests.escript | 94 |
14 files changed, 490 insertions, 0 deletions
diff --git a/deps/mochiweb/priv/skel/Makefile b/deps/mochiweb/priv/skel/Makefile new file mode 100644 index 00000000..615fa90a --- /dev/null +++ b/deps/mochiweb/priv/skel/Makefile @@ -0,0 +1,20 @@ +all: ebin/ + (cd src;$(MAKE) all) + +edoc: + (cd src;$(MAKE) edoc) + +test: + (cd src;$(MAKE) test) + +clean: + (cd src;$(MAKE) clean) + +clean_plt: + (cd src;$(MAKE) clean_plt) + +dialyzer: + (cd src;$(MAKE) dialyzer) + +ebin/: + @mkdir -p ebin diff --git a/deps/mochiweb/priv/skel/priv/www/index.html b/deps/mochiweb/priv/skel/priv/www/index.html new file mode 100644 index 00000000..8e7a2c62 --- /dev/null +++ b/deps/mochiweb/priv/skel/priv/www/index.html @@ -0,0 +1,8 @@ +<html> +<head> +<title>It Worked</title> +</head> +<body> +MochiWeb running. +</body> +</html> diff --git a/deps/mochiweb/priv/skel/src/Makefile b/deps/mochiweb/priv/skel/src/Makefile new file mode 100644 index 00000000..97fec1a1 --- /dev/null +++ b/deps/mochiweb/priv/skel/src/Makefile @@ -0,0 +1,33 @@ +include ../support/include.mk + +APPLICATION=skel +DOC_OPTS={dir,\"../doc\"} +TEST_PLT=$(TEST_DIR)/dialyzer_plt + +all: $(EBIN_FILES) + +debug: + $(MAKE) DEBUG=-DDEBUG + +clean: + rm -rf $(EBIN_FILES) + +edoc: + $(ERL) -noshell -pa ../ebin \ + -eval "edoc:application($(APPLICATION), \".\", [$(DOC_OPTS)])" \ + -s init stop + +test: $(EBIN_FILES) + mkdir -p $(TEST_DIR); + @../support/run_tests.escript $(EBIN_DIR) | tee $(TEST_DIR)/test.log + +$(TEST_PLT): + mkdir -p $(TEST_DIR) + cp $(DIALYZER_PLT) $(TEST_PLT) + dialyzer --plt $(TEST_PLT) --add_to_plt -r ../deps/*/ebin + +clean_plt: + rm $(TEST_PLT) + +dialyzer: $(TEST_PLT) + dialyzer --src --plt $(TEST_PLT) -DNOTEST -DDIALYZER -c ../src | tee $(TEST_DIR)/dialyzer.log
\ No newline at end of file diff --git a/deps/mochiweb/priv/skel/src/skel.app b/deps/mochiweb/priv/skel/src/skel.app new file mode 100644 index 00000000..fc16aae0 --- /dev/null +++ b/deps/mochiweb/priv/skel/src/skel.app @@ -0,0 +1,14 @@ +{application, skel, + [{description, "skel"}, + {vsn, "0.01"}, + {modules, [ + skel, + skel_app, + skel_sup, + skel_web, + skel_deps + ]}, + {registered, []}, + {mod, {skel_app, []}}, + {env, []}, + {applications, [kernel, stdlib, crypto]}]}. diff --git a/deps/mochiweb/priv/skel/src/skel.erl b/deps/mochiweb/priv/skel/src/skel.erl new file mode 100644 index 00000000..7ac4e2bc --- /dev/null +++ b/deps/mochiweb/priv/skel/src/skel.erl @@ -0,0 +1,30 @@ +%% @author author <author@example.com> +%% @copyright YYYY author. + +%% @doc TEMPLATE. + +-module(skel). +-author('author <author@example.com>'). +-export([start/0, stop/0]). + +ensure_started(App) -> + case application:start(App) of + ok -> + ok; + {error, {already_started, App}} -> + ok + end. + +%% @spec start() -> ok +%% @doc Start the skel server. +start() -> + skel_deps:ensure(), + ensure_started(crypto), + application:start(skel). + +%% @spec stop() -> ok +%% @doc Stop the skel server. +stop() -> + Res = application:stop(skel), + application:stop(crypto), + Res. diff --git a/deps/mochiweb/priv/skel/src/skel.hrl b/deps/mochiweb/priv/skel/src/skel.hrl new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/deps/mochiweb/priv/skel/src/skel.hrl @@ -0,0 +1 @@ + diff --git a/deps/mochiweb/priv/skel/src/skel_app.erl b/deps/mochiweb/priv/skel/src/skel_app.erl new file mode 100644 index 00000000..7ee8b50e --- /dev/null +++ b/deps/mochiweb/priv/skel/src/skel_app.erl @@ -0,0 +1,30 @@ +%% @author author <author@example.com> +%% @copyright YYYY author. + +%% @doc Callbacks for the skel application. + +-module(skel_app). +-author('author <author@example.com>'). + +-behaviour(application). +-export([start/2, stop/1]). + + +%% @spec start(_Type, _StartArgs) -> ServerRet +%% @doc application start callback for skel. +start(_Type, _StartArgs) -> + skel_deps:ensure(), + skel_sup:start_link(). + +%% @spec stop(_State) -> ServerRet +%% @doc application stop callback for skel. +stop(_State) -> + ok. + + +%% +%% Tests +%% +-include_lib("eunit/include/eunit.hrl"). +-ifdef(TEST). +-endif. diff --git a/deps/mochiweb/priv/skel/src/skel_deps.erl b/deps/mochiweb/priv/skel/src/skel_deps.erl new file mode 100644 index 00000000..cba796b1 --- /dev/null +++ b/deps/mochiweb/priv/skel/src/skel_deps.erl @@ -0,0 +1,92 @@ +%% @author author <author@example.com> +%% @copyright YYYY author. + +%% @doc Ensure that the relatively-installed dependencies are on the code +%% loading path, and locate resources relative +%% to this application's path. + +-module(skel_deps). +-author('author <author@example.com>'). + +-export([ensure/0, ensure/1]). +-export([get_base_dir/0, get_base_dir/1]). +-export([local_path/1, local_path/2]). +-export([deps_on_path/0, new_siblings/1]). + +%% @spec deps_on_path() -> [ProjNameAndVers] +%% @doc List of project dependencies on the path. +deps_on_path() -> + F = fun (X, Acc) -> + ProjDir = filename:dirname(X), + case {filename:basename(X), + filename:basename(filename:dirname(ProjDir))} of + {"ebin", "deps"} -> + [filename:basename(ProjDir) | Acc]; + _ -> + Acc + end + end, + ordsets:from_list(lists:foldl(F, [], code:get_path())). + +%% @spec new_siblings(Module) -> [Dir] +%% @doc Find new siblings paths relative to Module that aren't already on the +%% code path. +new_siblings(Module) -> + Existing = deps_on_path(), + SiblingEbin = filelib:wildcard(local_path(["deps", "*", "ebin"], Module)), + Siblings = [filename:dirname(X) || X <- SiblingEbin, + ordsets:is_element( + filename:basename(filename:dirname(X)), + Existing) =:= false], + lists:filter(fun filelib:is_dir/1, + lists:append([[filename:join([X, "ebin"]), + filename:join([X, "include"])] || + X <- Siblings])). + + +%% @spec ensure(Module) -> ok +%% @doc Ensure that all ebin and include paths for dependencies +%% of the application for Module are on the code path. +ensure(Module) -> + code:add_paths(new_siblings(Module)), + code:clash(), + ok. + +%% @spec ensure() -> ok +%% @doc Ensure that the ebin and include paths for dependencies of +%% this application are on the code path. Equivalent to +%% ensure(?Module). +ensure() -> + ensure(?MODULE). + +%% @spec get_base_dir(Module) -> string() +%% @doc Return the application directory for Module. It assumes Module is in +%% a standard OTP layout application in the ebin or src directory. +get_base_dir(Module) -> + {file, Here} = code:is_loaded(Module), + filename:dirname(filename:dirname(Here)). + +%% @spec get_base_dir() -> string() +%% @doc Return the application directory for this application. Equivalent to +%% get_base_dir(?MODULE). +get_base_dir() -> + get_base_dir(?MODULE). + +%% @spec local_path([string()], Module) -> string() +%% @doc Return an application-relative directory from Module's application. +local_path(Components, Module) -> + filename:join([get_base_dir(Module) | Components]). + +%% @spec local_path(Components) -> string() +%% @doc Return an application-relative directory for this application. +%% Equivalent to local_path(Components, ?MODULE). +local_path(Components) -> + local_path(Components, ?MODULE). + + +%% +%% Tests +%% +-include_lib("eunit/include/eunit.hrl"). +-ifdef(TEST). +-endif. diff --git a/deps/mochiweb/priv/skel/src/skel_sup.erl b/deps/mochiweb/priv/skel/src/skel_sup.erl new file mode 100644 index 00000000..1add1903 --- /dev/null +++ b/deps/mochiweb/priv/skel/src/skel_sup.erl @@ -0,0 +1,62 @@ +%% @author author <author@example.com> +%% @copyright YYYY author. + +%% @doc Supervisor for the skel application. + +-module(skel_sup). +-author('author <author@example.com>'). + +-behaviour(supervisor). + +%% External exports +-export([start_link/0, upgrade/0]). + +%% supervisor callbacks +-export([init/1]). + +%% @spec start_link() -> ServerRet +%% @doc API for starting the supervisor. +start_link() -> + supervisor:start_link({local, ?MODULE}, ?MODULE, []). + +%% @spec upgrade() -> ok +%% @doc Add processes if necessary. +upgrade() -> + {ok, {_, Specs}} = init([]), + + Old = sets:from_list( + [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]), + New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]), + Kill = sets:subtract(Old, New), + + sets:fold(fun (Id, ok) -> + supervisor:terminate_child(?MODULE, Id), + supervisor:delete_child(?MODULE, Id), + ok + end, ok, Kill), + + [supervisor:start_child(?MODULE, Spec) || Spec <- Specs], + ok. + +%% @spec init([]) -> SupervisorTree +%% @doc supervisor callback. +init([]) -> + Ip = case os:getenv("MOCHIWEB_IP") of false -> "0.0.0.0"; Any -> Any end, + WebConfig = [ + {ip, Ip}, + {port, 8000}, + {docroot, skel_deps:local_path(["priv", "www"])}], + Web = {skel_web, + {skel_web, start, [WebConfig]}, + permanent, 5000, worker, dynamic}, + + Processes = [Web], + {ok, {{one_for_one, 10, 10}, Processes}}. + + +%% +%% Tests +%% +-include_lib("eunit/include/eunit.hrl"). +-ifdef(TEST). +-endif. diff --git a/deps/mochiweb/priv/skel/src/skel_web.erl b/deps/mochiweb/priv/skel/src/skel_web.erl new file mode 100644 index 00000000..67064cc5 --- /dev/null +++ b/deps/mochiweb/priv/skel/src/skel_web.erl @@ -0,0 +1,51 @@ +%% @author author <author@example.com> +%% @copyright YYYY author. + +%% @doc Web server for skel. + +-module(skel_web). +-author('author <author@example.com>'). + +-export([start/1, stop/0, loop/2]). + +%% External API + +start(Options) -> + {DocRoot, Options1} = get_option(docroot, Options), + Loop = fun (Req) -> + ?MODULE:loop(Req, DocRoot) + end, + mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]). + +stop() -> + mochiweb_http:stop(?MODULE). + +loop(Req, DocRoot) -> + "/" ++ Path = Req:get(path), + case Req:get(method) of + Method when Method =:= 'GET'; Method =:= 'HEAD' -> + case Path of + _ -> + Req:serve_file(Path, DocRoot) + end; + 'POST' -> + case Path of + _ -> + Req:not_found() + end; + _ -> + Req:respond({501, [], []}) + end. + +%% Internal API + +get_option(Option, Options) -> + {proplists:get_value(Option, Options), proplists:delete(Option, Options)}. + + +%% +%% Tests +%% +-include_lib("eunit/include/eunit.hrl"). +-ifdef(TEST). +-endif. diff --git a/deps/mochiweb/priv/skel/start-dev.sh b/deps/mochiweb/priv/skel/start-dev.sh new file mode 100755 index 00000000..f684cb07 --- /dev/null +++ b/deps/mochiweb/priv/skel/start-dev.sh @@ -0,0 +1,12 @@ +#!/bin/sh +cd `dirname $0` + +MAKE=make +case `uname` in +*BSD) + MAKE=gmake + ;; +esac + +"${MAKE}" +exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s reloader -s skel diff --git a/deps/mochiweb/priv/skel/start.sh b/deps/mochiweb/priv/skel/start.sh new file mode 100755 index 00000000..599f8e67 --- /dev/null +++ b/deps/mochiweb/priv/skel/start.sh @@ -0,0 +1,3 @@ +#!/bin/sh +cd `dirname $0` +exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s skel diff --git a/deps/mochiweb/priv/skel/support/include.mk b/deps/mochiweb/priv/skel/support/include.mk new file mode 100644 index 00000000..bcba2142 --- /dev/null +++ b/deps/mochiweb/priv/skel/support/include.mk @@ -0,0 +1,40 @@ +## -*- makefile -*- + +###################################################################### +## Erlang + +ERL := erl +ERLC := $(ERL)c + +INCLUDE_DIRS := ../include $(wildcard ../deps/*/include) +EBIN_DIRS := $(wildcard ../deps/*/ebin) +ERLC_FLAGS := -W $(INCLUDE_DIRS:../%=-I ../%) $(EBIN_DIRS:%=-pa %) + +ifndef no_debug_info + ERLC_FLAGS += +debug_info +endif + +ifdef debug + ERLC_FLAGS += -Ddebug +endif + +EBIN_DIR := ../ebin +TEST_DIR := ../_test +EMULATOR := beam + +ERL_SOURCES := $(wildcard *.erl) +ERL_HEADERS := $(wildcard *.hrl) $(wildcard ../include/*.hrl) +ERL_OBJECTS := $(ERL_SOURCES:%.erl=$(EBIN_DIR)/%.$(EMULATOR)) +ERL_OBJECTS_LOCAL := $(ERL_SOURCES:%.erl=./%.$(EMULATOR)) +APP_FILES := $(wildcard *.app) +EBIN_FILES = $(ERL_OBJECTS) $(APP_FILES:%.app=../ebin/%.app) +MODULES = $(ERL_SOURCES:%.erl=%) + +../ebin/%.app: %.app + cp $< $@ + +$(EBIN_DIR)/%.$(EMULATOR): %.erl + $(ERLC) $(ERLC_FLAGS) -o $(EBIN_DIR) $< + +./%.$(EMULATOR): %.erl + $(ERLC) $(ERLC_FLAGS) -o . $< diff --git a/deps/mochiweb/priv/skel/support/run_tests.escript b/deps/mochiweb/priv/skel/support/run_tests.escript new file mode 100755 index 00000000..ff49c064 --- /dev/null +++ b/deps/mochiweb/priv/skel/support/run_tests.escript @@ -0,0 +1,94 @@ +#!/usr/bin/env escript +%% -*- erlang -*- +%%! -name mochiweb__test@127.0.0.1 +main([Ebin]) -> + code:add_path(Ebin), + code:add_paths(filelib:wildcard("../deps/*/ebin", Ebin)), + code:add_paths(filelib:wildcard("../deps/*/deps/*/ebin", Ebin)), + + ModuleNames = [hd(string:tokens(M, ".")) + || "../src/" ++ M <- filelib:wildcard("../src/*.erl")], + + {ok, NonTestRe} = re:compile("_tests$"), + Modules = [list_to_atom(M) || + M <- lists:filter( + fun(M) -> + nomatch == re:run(M, NonTestRe) + end, + ModuleNames)], + + + crypto:start(), + start_cover(Modules), + eunit:test(Modules, [verbose,{report,{eunit_surefire,[{dir,"../_test"}]}}]), + analyze_cover(Modules); +main(_) -> + io:format("usage: run_tests.escript EBIN_DIR~n"), + halt(1). + +start_cover(Modules) -> + {ok, _Cover} = cover:start(), + io:format("Cover compiling...~n"), + Compiled = [ M || {ok, M} <- [ cover:compile( + M, + [{i, "include"} + ]) + || M <- Modules ] ], + case length(Modules) == length(Compiled) of + true -> ok; + false -> + io:format("Warning: the following modules were not" + " cover-compiled:~n ~p~n", [Compiled]) + end. + +analyze_cover(Modules) -> + io:format("Analyzing cover...~n"), + CoverBase = filename:join(["..", "_test", "cover"]), + ok = filelib:ensure_dir(filename:join([CoverBase, "fake"])), + Coverages = lists:foldl( + fun(M, Acc) -> + [analyze_module(CoverBase, M)|Acc] + end, + [], Modules), + IndexFilename = filename:join([CoverBase, "index.html"]), + {ok, Index} = file:open(IndexFilename, [write]), + {LineTotal, CoverTotal} = + lists:foldl(fun({_,_,Lines,Covered}, {LineAcc, CovAcc}) -> + {LineAcc+Lines, CovAcc+Covered} + end, {0,0}, Coverages), + file:write(Index, + "<html><head><title>Coverage</title></head>\n" + "<body><h1>Coverage</h1><ul>\n"), + file:write(Index, + io_lib:format("<h2>Total: ~.2f%</h2>\n", + [percentage(CoverTotal, LineTotal)])), + [ file:write(Index, + io_lib:format( + "<li><a href=\"~s\">~p</a>: ~.2f%</li>~n", + [Filename, Module, percentage(Covered, Lines)])) + || {Filename, Module, Lines, Covered} <- Coverages ], + file:write(Index,"</ul></body></html>"), + file:close(Index), + io:format("Cover analysis in ~s~n", [IndexFilename]). + +analyze_module(CoverBase, Module) -> + {ok, Filename} = + cover:analyze_to_file( + Module, + filename:join(CoverBase, atom_to_list(Module)++".COVER.html"), + [html]), + Lines = count_lines(Filename, "[[:digit:]]\.\.|"), + Covered = count_lines(Filename, "[[:space:]]0\.\.|"), + {filename:basename(Filename), Module, Lines, Lines-Covered}. + +count_lines(Filename, Pattern) -> + {ok, [Lines],_} = io_lib:fread( + "~d", + os:cmd(io_lib:format("grep -e \"~s\" ~s | wc -l", + [Pattern, Filename]))), + Lines. + +percentage(_, 0) -> 1000.0; +percentage(Part, Total) -> + (Part/Total)*100. + |