1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 2002, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
24
-import(lists, [foldl/3, foreach/2, map/2, member/2]).
26
%% ear -a Archive Mod Mod Dir
28
%% ear -d Archive Mod Mod
31
%% Note ear *cannot* be used to build the origonal
32
%% erlang.ear (since erlang.ear) is used for the code base for
34
%% Erlang.ear is build inside boot_tools.erl
37
%% ear -a foo.ear /ldisk/otp_src_P9_2002-05-26/lib/kernel/ebin/*.beam
40
%% we want all these commands to work like a transaction
41
%% their every works or nothing.
42
%% This means we do all checking *before* manipulating the
46
X0 = map(fun(I) -> binary_to_list(I) end, X),
47
%% io:format("EAR:~p~n",[X0]),
52
ear(["-l", Archive]) ->
54
Pid = boot_pds:open(Archive, read),
55
Keys = lists:sort(boot_pds:keys(Pid)),
56
foreach(fun(I) -> io:format("~s~n", [print_name(I)]) end, Keys),
58
ear(["-a", Archive|Objs]) ->
60
Updates = foldl(fun add_object/2, [], Objs),
61
Pid = boot_pds:open(Archive, read_write),
62
map(fun({add,Key,Val}) ->
63
boot_pds:store(Pid, Key, Val)
66
ear(["-r", Archive|Objs]) ->
68
Delete = map(fun get_obj_name/1, Objs),
69
%% io:format("delete=~p~n",[Delete]),
70
Pid = boot_pds:open(Archive, read_write),
71
Keys = boot_pds:keys(Pid),
73
case member(I, Keys) of
78
io:format("*** archive does not have element:~s~n",
83
foreach(fun(I) -> boot_pds:delete(Pid, I) end, Delete),
85
ear(["-e", Archive|Objs]) ->
87
Extract = map(fun get_obj_name/1, Objs),
88
%% io:format("extract=~p~n",[Extract]),
89
Pid = boot_pds:open(Archive, read_write),
90
Keys = boot_pds:keys(Pid),
91
%% check the archive has the required element
93
case member(I, Keys) of
98
io:format("*** archive does not have element:~s~n",
103
%% check we won't clobber the file
109
io:format("*** ~s exists and will not be "
117
%% Finally extract the files
120
{ok, Bin} = boot_pds:fetch(Pid, I),
121
file:write_file(F, Bin)
130
case boot_fprim:read_file_info(File) of
136
case filename:extension(F) of
140
io:format("*** ~s is not an archive (.ear file)~n", [F]),
144
print_name({mod, I}) -> atom_to_list(I) ++ ".beam";
145
print_name({include,F}) -> F ++ ".hrl".
148
case filename:extension(Obj) of
150
F1 = filename:rootname(filename:basename(Obj)),
151
A = list_to_atom(F1),
154
F1 = filename:rootname(filename:basename(Obj)),
157
io:format("*** ~s not .beam or .hrl~n", [Obj]),
161
add_object(Obj, L) ->
162
case filename:extension(Obj) of
164
case get_module_name(Obj) of
166
{ok, Bin} = file:read_file(Obj),
167
[{add, {mod,Mod}, Bin}|L];
169
io:format("** bad module :~s~n", [Obj]),
173
F1 = filename:rootname(filename:basename(Obj)),
174
case file:read_file(Obj) of
176
[{add, {include, F1}, Bin}|L];
178
io:format("** bad include file :~s~n", [Obj]),
182
io:format("** bad extension :~s~n", [Obj]),
186
get_module_name(F) ->
187
case beam_lib:info(F) of
189
case [M || {module, M} <- L] of
200
io:format("Usage: ear [-l |-a |-r |-e] archive files\n"
204
" l - list archive\n"
205
" a - add file(s) to archive\n"
206
" r - remove file(s) from archive\n"
207
" e - extract file(s) from archive\n"
209
" archive files must have the extension .ear\n"
210
" archived files may have extensions .beam or .hrl\n"
212
" > ear -a myLib.ear *.beam my_include.hrl\n"
213
" > ear -a myLib.ear PathToLib/ebin/*.beam\n"
214
" > ear -a myLib.ear PathToLib/include/*.hrl\n").