summaryrefslogtreecommitdiff
path: root/src/rebar_appups.erl
diff options
context:
space:
mode:
authorjoewilliams <joe@joetify.com>2011-05-23 18:17:03 -0700
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2011-05-24 10:48:19 +0200
commitb7e20f323425938f2f180986e1a9f6a1e05ee25a (patch)
treee8015c1b7e058a12c8bb8a48c3064a4ea5b5537c /src/rebar_appups.erl
parent1628879b213cb0afff5d5a6ecb4aa4b4eeeba4ab (diff)
downloadrebar-b7e20f323425938f2f180986e1a9f6a1e05ee25a.tar.gz
Better org. of how upgraded apps are determined
get_apps/3 now returns which apps have been added, removed and ugpgraded in a reasonable way. It should prove more usable should we want to access any of those lists in future appup related changes.
Diffstat (limited to 'src/rebar_appups.erl')
-rw-r--r--src/rebar_appups.erl51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/rebar_appups.erl b/src/rebar_appups.erl
index 079d596..df20e43 100644
--- a/src/rebar_appups.erl
+++ b/src/rebar_appups.erl
@@ -56,7 +56,7 @@
"Reltool and .rel release names do not match~n", []),
%% Find all the apps that have been upgraded
- UpgradedApps = get_upgraded_apps(Name, OldVerPath, NewVerPath),
+ {_Added, _Removed, Upgraded} = get_apps(Name, OldVerPath, NewVerPath),
%% Get a list of any appup files that exist in the new release
NewAppUpFiles = rebar_utils:find_files(
@@ -68,10 +68,10 @@
end, NewAppUpFiles),
%% Create a list of apps that don't already have appups
- Apps = genappup_which_apps(UpgradedApps, AppUpApps),
+ UpgradeApps = genappup_which_apps(Upgraded, AppUpApps),
- %% Generate appup files
- generate_appup_files(Name, OldVerPath, Apps),
+ %% Generate appup files for upgraded apps
+ generate_appup_files(Name, OldVerPath, UpgradeApps),
ok.
@@ -79,24 +79,43 @@
%% Internal functions
%% ===================================================================
-get_upgraded_apps(Name, OldVerPath, NewVerPath) ->
+get_apps(Name, OldVerPath, NewVerPath) ->
OldApps = rebar_rel_utils:get_rel_apps(Name, OldVerPath),
+ ?DEBUG("Old Version Apps: ~p~n", [OldApps]),
+
NewApps = rebar_rel_utils:get_rel_apps(Name, NewVerPath),
+ ?DEBUG("New Version Apps: ~p~n", [NewApps]),
+
+ Added = app_list_diff(NewApps, OldApps),
+ ?DEBUG("Added: ~p~n", [Added]),
+
+ Removed = app_list_diff(OldApps, NewApps),
+ ?DEBUG("Removed: ~p~n", [Removed]),
+
+ PossiblyUpgraded = proplists:get_keys(NewApps),
+
+ UpgradedApps = [upgraded_app(AppName,
+ proplists:get_value(AppName, OldApps),
+ proplists:get_value(AppName, NewApps))
+ || AppName <- PossiblyUpgraded],
+
+ Upgraded = lists:dropwhile(fun(Elem) ->
+ Elem == false
+ end, lists:sort(UpgradedApps)),
- Sorted = lists:umerge(lists:sort(NewApps), lists:sort(OldApps)),
- AddedorChanged = lists:subtract(Sorted, OldApps),
- DeletedorChanged = lists:subtract(Sorted, NewApps),
- ?DEBUG("Added or Changed: ~p~n", [AddedorChanged]),
- ?DEBUG("Deleted or Changed: ~p~n", [DeletedorChanged]),
+ ?DEBUG("Upgraded: ~p~n", [Upgraded]),
- AddedDeletedChanged = lists:ukeysort(1, lists:append(DeletedorChanged,
- AddedorChanged)),
- UpgradedApps = lists:subtract(AddedorChanged, AddedDeletedChanged),
- ?DEBUG("Upgraded Apps:~p~n", [UpgradedApps]),
+ {Added, Removed, Upgraded}.
- [{AppName, {proplists:get_value(AppName, OldApps), NewVer}}
- || {AppName, NewVer} <- UpgradedApps].
+upgraded_app(AppName, OldAppVer, NewAppVer) when OldAppVer /= NewAppVer ->
+ {AppName, {OldAppVer, NewAppVer}};
+upgraded_app(_, _, _) ->
+ false.
+app_list_diff(List1, List2) ->
+ List3 = lists:umerge(lists:sort(proplists:get_keys(List1)),
+ lists:sort(proplists:get_keys(List2))),
+ lists:subtract(List3, proplists:get_keys(List2)).
file_to_name(File) ->
filename:rootname(filename:basename(File)).