---
 features/sin_gen_app_src.feature |   12 +++++++
 src/sin_gen.erl                  |   62 +++++++++++++++++++-------------------
 test/sin_app_src.erl             |    7 +++-
 test/sin_gen_app_src.erl         |   47 ++++++++++++++++++++++++++++
 test/sin_test_project_gen.erl    |    5 ++-
 5 files changed, 99 insertions(+), 34 deletions(-)
 create mode 100644 features/sin_gen_app_src.feature
 create mode 100644 test/sin_gen_app_src.erl

diff --git a/features/sin_gen_app_src.feature b/features/sin_gen_app_src.feature
new file mode 100644
index 0000000..428c1fc
--- /dev/null
+++ b/features/sin_gen_app_src.feature
@@ -0,0 +1,12 @@
+Feature: sinan gen should support generating *.app.src instead of ebin/app
+  In order to make a sinan generated project 'correct'
+  As an Erlang Developer
+  I want sinan to generate application metadata into src/<appname>.app.src
+  instead of ebin/<appname>.app
+
+  Scenario: Generate app.src into the src directory
+    Given an empty temp directory with no project
+    When the sinan gen task is called
+    And a build is run
+    Then sinan should generate an app.src into the src directory
+    And build the project normally
diff --git a/src/sin_gen.erl b/src/sin_gen.erl
index bda2ce6..7c1edfa 100644
--- a/src/sin_gen.erl
+++ b/src/sin_gen.erl
@@ -46,15 +46,15 @@ build_out_skeleton(Env) ->
 -spec build_out_applications(env()) -> ok.
 build_out_applications(Env) ->
     case get_env(single_app_project, Env) of
-       false ->
-           Apps = get_env(apps, Env),
-           build_out_applications(Env, Apps);
-       true ->
-           ProjDir = get_env(project_dir, Env),
-           ProjVsn = get_env(project_version, Env),
-           ProjName = get_env(project_name, Env),
-           build_out_application(Env, ProjDir, ProjName, ProjVsn),
-           build_out_build_config(Env)
+        false ->
+            Apps = get_env(apps, Env),
+            build_out_applications(Env, Apps);
+        true ->
+            ProjDir = get_env(project_dir, Env),
+            ProjVsn = get_env(project_version, Env),
+            ProjName = get_env(project_name, Env),
+            build_out_application(Env, ProjDir, ProjName, ProjVsn),
+            build_out_build_config(Env)
     end.
 
 -spec build_out_applications(env(), AppNames::[string()]) -> ok.
@@ -68,14 +68,14 @@ build_out_applications(Env, []) ->
 
 %% @doc build out all the things required by an application
 -spec build_out_application(env(), AppDir::string(),
-                           AppName::string(), AppVsn::string()) -> ok.
+                            AppName::string(), AppVsn::string()) -> ok.
 build_out_application(Env, AppDir, AppName, AppVsn) ->
     EbinDir = make_dir(filename:join(AppDir, "ebin")),
     AppSrc = make_dir(filename:join(AppDir, "src")),
     make_dir(filename:join(AppDir, "include")),
     make_dir(filename:join(AppDir, "doc")),
     build_out_super(Env, AppSrc, AppName),
-    build_out_app_src(Env, EbinDir, AppName, AppVsn),
+    build_out_app_src(Env, AppSrc, AppName, AppVsn),
     build_out_otp(Env, AppSrc, AppName),
     build_out_app_doc(Env, EbinDir, AppName).
 
@@ -92,14 +92,14 @@ build_out_super(Env, AppSrc, AppName) ->
 
 %% @doc Builds out the app descriptor for the app.
 -spec build_out_app_src(env(), EbinDir::string(),
-                       AppName::string(), AppVsn::string()) -> ok.
-build_out_app_src(Env, EbinDir, AppName, AppVsn) ->
-    FileName = filename:join(EbinDir, AppName ++ ".app"),
+                        AppName::string(), AppVsn::string()) -> ok.
+build_out_app_src(Env, AppSrc, AppName, AppVsn) ->
+    FileName = filename:join(AppSrc, AppName ++ ".app.src"),
     case filelib:is_file(FileName) of
         true ->
             ok;
         false ->
-           sin_skel:app_info(Env, FileName, AppName, AppVsn)
+            sin_skel:app_info(Env, FileName, AppName, AppVsn)
     end.
 
 %% @doc Builds out the overview.edoc for the app.
@@ -119,7 +119,7 @@ build_out_otp(Env, AppSrc, AppName) ->
     FileName = filename:join(AppSrc, AppName ++ "_app.erl"),
     case filelib:is_file(FileName) of
         true ->
-           ok;
+            ok;
         false ->
             sin_skel:application(Env, FileName, AppName)
     end.
@@ -127,21 +127,21 @@ build_out_otp(Env, AppSrc, AppName) ->
 %% @doc Builds the build config dir in the root of the project.
 build_out_build_config(Env) ->
     case get_env(wants_build_config, Env) of
-       true ->
-           ProjectDir = get_env(project_dir, Env),
-           ProjectName = get_env(project_name, Env),
-           ConfName = filename:join([ProjectDir, "sinan.cfg"]),
-           ErlwareFile =
-               filename:join([ProjectDir,  "bin",
-                              "erlware_release_start_helper"]),
-           BinFile = filename:join([ProjectDir,  "bin", ProjectName]),
-           ConfigFile = filename:join([ProjectDir,  "config", "sys.config"]),
-           sin_skel:build_config(Env, ConfName),
-           sin_skel:bin(Env, BinFile),
-           sin_skel:bin_support(Env, ErlwareFile),
-           sin_skel:sysconfig(Env, ConfigFile);
-       false ->
-           ok
+        true ->
+            ProjectDir = get_env(project_dir, Env),
+            ProjectName = get_env(project_name, Env),
+            ConfName = filename:join([ProjectDir, "sinan.cfg"]),
+            ErlwareFile =
+                filename:join([ProjectDir,  "bin",
+                               "erlware_release_start_helper"]),
+            BinFile = filename:join([ProjectDir,  "bin", ProjectName]),
+            ConfigFile = filename:join([ProjectDir,  "config", "sys.config"]),
+            sin_skel:build_config(Env, ConfName),
+            sin_skel:bin(Env, BinFile),
+            sin_skel:bin_support(Env, ErlwareFile),
+            sin_skel:sysconfig(Env, ConfigFile);
+        false ->
+            ok
     end.
 
 %% @doc Helper function that makes the specified directory and all parent
diff --git a/test/sin_app_src.erl b/test/sin_app_src.erl
index e85c7dc..0237903 100644
--- a/test/sin_app_src.erl
+++ b/test/sin_app_src.erl
@@ -10,6 +10,8 @@ given([a, generated, project, that, contains, an, 'ebin/app'],
     ProjectName = "super_foo",
     {ProjectDir, _} =
         sin_test_project_gen:single_app_project(BaseDir, ProjectName),
+    AppEbin = filename:join([ProjectDir, "ebin", ProjectName ++ ".app"]),
+    ?assertMatch(ok, file:write_file(AppEbin, app_src(ProjectName))),
     {ok, {ProjectDir, ProjectName}};
 given([a,generated,project,that,contains,an,'app.src'], _State, _) ->
       {ok, BaseDir} = ewl_file:create_tmp_dir("/tmp"),
@@ -33,9 +35,10 @@ given([does,'not',contain,an,'app.src'],
 given([contains,an,'ebin/app'],
       State = {ProjectDir, ProjectName}, _) ->
     %% Generated by default so lets just make sure it exists
-    AppSrc = filename:join([ProjectDir, "ebin", ProjectName ++ ".app"]),
+    AppEbin = filename:join([ProjectDir, "ebin", ProjectName ++ ".app"]),
+    ?assertMatch(ok, file:write_file(AppEbin, app_src(ProjectName))),
     ?assertMatch(true,
-                 sin_utils:file_exists(sin_config:new(), AppSrc)),
+                 sin_utils:file_exists(sin_config:new(), AppEbin)),
     {ok, State}.
 
 'when'([a, build, step, is, run, on, this, project],
diff --git a/test/sin_gen_app_src.erl b/test/sin_gen_app_src.erl
new file mode 100644
index 0000000..992d23b
--- /dev/null
+++ b/test/sin_gen_app_src.erl
@@ -0,0 +1,47 @@
+%%%-------------------------------------------------------------------
+%%% @copyright (C) 2011, Erlware, LLC.
+%%% @doc
+%%%  Test the ability to generate an app.src
+%%% @end
+%%% Created :  5 Sep 2011 by Eric Merritt <[email protected]>
+%%%-------------------------------------------------------------------
+-module(sin_gen_app_src).
+
+-include_lib("eunit/include/eunit.hrl").
+
+-export([given/3, 'when'/3, then/3]).
+
+% Step definitions for the sample calculator Addition feature.
+
+given([an, empty, temp, directory, with, no, project], _State,
+      _) ->
+    {ok, BaseDir} = ewl_file:create_tmp_dir("/tmp"),
+    {ok, BaseDir}.
+
+'when'([the, sinan, gen, task, is, called], BaseDir, _) ->
+    ProjectName = "super_foo",
+    {ProjectDir, _} =
+        sin_test_project_gen:single_app_project(BaseDir, ProjectName),
+    {ok, {ProjectDir, ProjectName}};
+'when'([a, build, is, run],
+       {ProjectDir, ProjectName}, _) ->
+    Ret = sinan:run_sinan(["-s", ProjectDir, "build"]),
+    {ok, {ProjectDir, ProjectName, Ret}}.
+
+
+then([sinan, should, generate, an, 'app.src',
+      into, the, src, directory],
+     State = {ProjectDir, ProjectName, _}, _) ->
+    Path = filename:join([ProjectDir, "src",
+                          ProjectName ++ ".app.src"]),
+
+    ?assertMatch(true,
+                 sin_utils:file_exists(sin_config:new(), Path)),
+
+    {ok, State};
+then([build, the, project, normally],
+    State = {ProjectDir, ProjectName, BuildState}, _) ->
+    ?assertMatch({ok, _}, BuildState),
+    sin_test_project_gen:validate_single_app_project(ProjectDir,
+                                                     ProjectName),
+    {ok, State}.
diff --git a/test/sin_test_project_gen.erl b/test/sin_test_project_gen.erl
index b21fcb6..7994f9f 100644
--- a/test/sin_test_project_gen.erl
+++ b/test/sin_test_project_gen.erl
@@ -34,6 +34,10 @@ validate_single_app_project(ProjectDir, ProjectName) ->
     ?assertMatch(true, filelib:is_regular(filename:join([Config, 
"sys.config"]))),
     Src = filename:join([ProjectDir, "src"]),
     ?assertMatch(true, filelib:is_file(Src)),
+    ?assertMatch(true,
+                 filelib:is_regular(filename:join([Src,
+                                                   ProjectName ++ 
".app.src"]))),
+
     ?assertMatch(true, filelib:is_regular(filename:join([Src, ProjectName ++ 
"_app.erl"]))),
     ?assertMatch(true, filelib:is_regular(filename:join([Src, ProjectName ++ 
"_sup.erl"]))),
     ?assertMatch(true, filelib:is_file(filename:join([ProjectDir, 
"include"]))),
@@ -44,7 +48,6 @@ validate_single_app_project(ProjectDir, ProjectName) ->
     ?assertMatch(true, filelib:is_regular(filename:join([Bin, ProjectName]))),
     EBin = filename:join([ProjectDir, "ebin"]),
     ?assertMatch(true, filelib:is_file(EBin)),
-    ?assertMatch(true, filelib:is_regular(filename:join([EBin, ProjectName ++ 
".app"]))),
     ?assertMatch(true, filelib:is_regular(filename:join([EBin, 
"overview.edoc"]))),
     AppDir = filename:join([ProjectDir, "_build", "development", "apps",
                             ProjectName ++ "-0.1.0"]),
-- 
1.7.5.2

-- 
You received this message because you are subscribed to the Google Groups 
"erlware-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/erlware-dev?hl=en.

Reply via email to