瀏覽代碼

Revert "Introduce rebar_uri to avoid deprecation warnings on OTP 23 [master]"

pull/2216/head
Fred Hebert 5 年之前
committed by GitHub
父節點
當前提交
386aa1a529
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 6 個文件被更改,包括 27 次插入133 次删除
  1. +2
    -2
      src/rebar_git_resource.erl
  2. +2
    -2
      src/rebar_hex_repos.erl
  3. +0
    -71
      src/rebar_uri.erl
  4. +15
    -8
      src/rebar_utils.erl
  5. +0
    -48
      test/rebar_uri_SUITE.erl
  6. +8
    -2
      test/rebar_utils_SUITE.erl

+ 2
- 2
src/rebar_git_resource.erl 查看文件

@ -117,8 +117,8 @@ parse_git_url(Url) ->
end.
parse_git_url(not_scp, Url) ->
UriOpts = [{scheme_defaults, [{git, 9418} | http_uri:scheme_defaults()]}],
case rebar_uri:parse(Url, UriOpts) of
#{path := Path, host := Host} ->
case http_uri:parse(Url, UriOpts) of
{ok, {_Scheme, _User, Host, _Port, Path, _Query}} ->
{ok, {Host, filename:rootname(Path, ".git")}};
{error, Reason} ->
{error, Reason}

+ 2
- 2
src/rebar_hex_repos.erl 查看文件

@ -96,8 +96,8 @@ update_organizations(Repos) ->
{ok, Parent} = get_repo_config(ParentName, Repos),
ParentRepoUrl = rebar_utils:to_list(maps:get(repo_url, Parent)),
{ok, _RepoUrl} =
rebar_uri:append_path(ParentRepoUrl,
filename:join("repos", rebar_utils:to_list(RepoName))),
rebar_utils:url_append_path(ParentRepoUrl,
filename:join("repos", rebar_utils:to_list(RepoName))),
%% still let the organization config override this constructed repo url
maps:merge(Parent#{repo_url => rebar_utils:to_binary(ParentRepoUrl)}, Repo);
(Repo) ->

+ 0
- 71
src/rebar_uri.erl 查看文件

@ -1,71 +0,0 @@
%%% @doc multi-OTP version compatibility shim for working with URIs
-module(rebar_uri).
-export([
parse/1,
append_path/2
]).
-import(rebar_utils, [to_list/1]).
-ifdef (OTP_RELEASE).
-spec parse(URIString) -> URIMap when
URIString :: uri_string:uri_string(),
URIMap :: uri_string:uri_map() | uri_string:error().
parse(URIString) ->
uri_string:parse(URIString).
-else.
-spec parse(URIString) -> URIMap when
URIString :: iodata(),
URIMap :: map() | {error, atom(), term()}.
parse(URIString) ->
case http_uri:parse(URIString) of
{error, Reason} ->
%% no additional parser/term info available to us,
%% e.g. see what uri_string returns in
%% uri_string:parse(<<"h$ttp:::://////lolz">>).
{error, Reason, ""};
{ok, {Scheme, UserInfo, Host, Port, Path, Query}} ->
#{
scheme => rebar_utils:to_list(Scheme),
host => Host,
port => Port,
path => Path,
%% http_uri:parse/1 includes the leading question mark
%% in query string but uri_string:parse/1 leaves it out.
%% string:slice/2 isn't available in OTP <= 19.
query => case Query of
[] -> "";
_ -> string:substr(Query, 2)
end,
userinfo => UserInfo
}
end.
-endif.
%% OTP 21+
-ifdef (OTP_RELEASE).
append_path(Url, ExtraPath) ->
case parse(Url) of
#{path := Path} = Map ->
FullPath = filename:join(Path, ExtraPath),
{ok, uri_string:recompose(maps:update(path, FullPath, Map))};
_ ->
error
end.
-else.
append_path(Url, ExtraPath) ->
case parse(Url) of
#{scheme := Scheme, userinfo := UserInfo, host := Host, port := Port, path := Path, query := Query} ->
PrefixedQuery = case Query of
[] -> [];
Other -> lists:append(["?", Other])
end,
{ok, lists:append([to_list(Scheme), "://", UserInfo, Host, ":", to_list(Port),
filename:join(Path, ExtraPath), PrefixedQuery])};
_ ->
error
end.
-endif.

+ 15
- 8
src/rebar_utils.erl 查看文件

@ -64,6 +64,7 @@
tup_find/2,
line_count/1,
set_httpc_options/0,
url_append_path/2,
escape_chars/1,
escape_double_quotes/1,
escape_double_quotes_weak/1,
@ -265,8 +266,6 @@ to_binary(A) when is_atom(A) -> atom_to_binary(A, unicode);
to_binary(Str) -> unicode:characters_to_binary(Str).
to_list(A) when is_atom(A) -> atom_to_list(A);
to_list(B) when is_binary(B) -> unicode:characters_to_list(B);
to_list(I) when is_integer(I) -> integer_to_list(I);
to_list(Str) -> unicode:characters_to_list(Str).
tup_dedup(List) ->
@ -911,7 +910,8 @@ get_http_vars(Scheme) ->
-ifdef (OTP_RELEASE).
-if(?OTP_RELEASE >= 23).
-compile({nowarn_deprecated_function, [{http_uri, decode, 1}]}).
-compile({nowarn_deprecated_function, [{http_uri, parse, 1},
{http_uri, decode, 1}]}).
-endif.
-endif.
@ -924,10 +924,7 @@ set_httpc_options(_, []) ->
set_httpc_options(Scheme, Proxy) ->
URI = normalise_proxy(Scheme, Proxy),
Parts = rebar_uri:parse(URI),
Host = maps:get(host, Parts, []),
Port = maps:get(port, Parts, []),
UserInfo = maps:get(userinfo, Parts, []),
{ok, {_, UserInfo, Host, Port, _, _}} = http_uri:parse(URI),
httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar),
set_proxy_auth(UserInfo).
@ -938,6 +935,15 @@ normalise_proxy(Scheme, URI) ->
_ -> URI
end.
url_append_path(Url, ExtraPath) ->
case http_uri:parse(Url) of
{ok, {Scheme, UserInfo, Host, Port, Path, Query}} ->
{ok, lists:append([atom_to_list(Scheme), "://", UserInfo, Host, ":", integer_to_list(Port),
filename:join(Path, ExtraPath), Query])};
_ ->
error
end.
%% escape\ as\ a\ shell\?
escape_chars(Str) when is_atom(Str) ->
escape_chars(atom_to_list(Str));
@ -1022,7 +1028,8 @@ ssl_opts(Url) ->
ssl_opts(ssl_verify_enabled, Url) ->
case check_ssl_version() of
true ->
#{host := Hostname} = rebar_uri:parse(rebar_utils:to_list(Url)),
{ok, {_, _, Hostname, _, _, _}} =
http_uri:parse(rebar_utils:to_list(Url)),
VerifyFun = {fun ssl_verify_hostname:verify_fun/3,
[{check_hostname, Hostname}]},
CACerts = certifi:cacerts(),

+ 0
- 48
test/rebar_uri_SUITE.erl 查看文件

@ -1,48 +0,0 @@
-module(rebar_uri_SUITE).
-export([all/0,
parse/1,
append_path/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("kernel/include/file.hrl").
all() ->
[parse].
parse(_Config) ->
#{scheme := Scheme, host := Host, path := Path} = rebar_uri:parse("https://repo.hex.pm"),
?assertEqual("https", Scheme),
?assertEqual("repo.hex.pm", Host),
?assert(lists:member(Path, ["", "/"])),
#{scheme := Scheme2, host := Host2, port := Port2, path := Path2, query := Query2} =
rebar_uri:parse("https://repo.hex.pm:443?foo=bar"),
?assertEqual("https", Scheme2),
?assertEqual("repo.hex.pm", Host2),
?assertEqual(443, Port2),
?assert(lists:member(Path2, ["", "/"])),
?assertEqual("foo=bar", Query2),
#{scheme := Scheme3, host := Host3, path := Path3, query := Query3} =
rebar_uri:parse("https://repo.hex.pm/over/here?foo=bar"),
?assertEqual("https", Scheme3),
?assertEqual("repo.hex.pm", Host3),
?assertEqual("/over/here", Path3),
?assertEqual("foo=bar", Query3).
append_path(_Config) ->
%% OTP version differences
{ok, Val1} = rebar_utils:append_path("https://repo.hex.pm", "/repos/org"),
?assert(lists:member(Val1, [
"https://repo.hex.pm/repos/org",
"https://repo.hex.pm:443/repos/org"
])),
{ok, Val2} = rebar_utils:append_path("https://repo.hex.pm?foo=bar", "/repos/org"),
?assert(lists:member(Val2, [
"https://repo.hex.pm/repos/org?foo=bar",
"https://repo.hex.pm:443/repos/org?foo=bar"
])),
?assertEqual({ok, "https://repo.hex.pm:443/repos/org?foo=bar"},
rebar_utils:append_path("https://repo.hex.pm:443?foo=bar", "/repos/org")).

+ 8
- 2
test/rebar_utils_SUITE.erl 查看文件

@ -33,7 +33,8 @@
sh_does_not_miss_messages/1,
tup_merge/1,
proxy_auth/1,
is_list_of_strings/1]).
is_list_of_strings/1,
url_append_path/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@ -49,7 +50,7 @@ all() ->
[{group, args_to_tasks},
sh_does_not_miss_messages,
tup_merge,
proxy_auth, is_list_of_strings].
proxy_auth, is_list_of_strings, url_append_path].
groups() ->
[{args_to_tasks, [], [empty_arglist,
@ -319,3 +320,8 @@ is_list_of_strings(_Config) ->
?assert(rebar_utils:is_list_of_strings([])),
?assert(rebar_utils:is_list_of_strings("")),
?assert(rebar_utils:is_list_of_strings("foo") == false).
url_append_path(_Config) ->
?assertEqual({ok, "https://repo.hex.pm:443/repos/org"}, rebar_utils:url_append_path("https://repo.hex.pm", "/repos/org")),
?assertEqual({ok, "https://repo.hex.pm:443/repos/org?foo=bar"}, rebar_utils:url_append_path("https://repo.hex.pm",
"/repos/org?foo=bar")).

Loading…
取消
儲存