@@ -25,9 +25,9 @@ defmodule Mix.Tasks.Local.Rebar do
2525
2626 ## Command line options
2727
28- * `rebar PATH` - specifies a path or URL for `rebar`
28+ * `rebar PATH` - specifies a path for `rebar`
2929
30- * `rebar3 PATH` - specifies a path or URL for `rebar3`
30+ * `rebar3 PATH` - specifies a path for `rebar3`
3131
3232 * `--sha512` - checks the archive matches the given SHA-512 checksum
3333
@@ -68,6 +68,8 @@ defmodule Mix.Tasks.Local.Rebar do
6868 defp install_from_path ( manager , path , opts ) do
6969 local = Mix.Rebar . local_rebar_path ( manager )
7070
71+ if file_url? ( path ) , do: warn_install_over_http_deprecated ( manager , path )
72+
7173 if opts [ :force ] || Mix.Generator . overwrite? ( local ) do
7274 case Mix.Utils . read_path ( path , opts ) do
7375 { :ok , binary } ->
@@ -77,7 +79,7 @@ defmodule Mix.Tasks.Local.Rebar do
7779 Mix . shell ( ) . info ( [ :green , "* creating " , :reset , Path . relative_to_cwd ( local ) ] )
7880
7981 :badpath ->
80- Mix . raise ( "Expected #{ inspect ( path ) } to be a URL or a local file path" )
82+ Mix . raise ( "Expected #{ inspect ( path ) } to be a local file path" )
8183
8284 { :local , message } ->
8385 Mix . raise ( message )
@@ -100,6 +102,10 @@ defmodule Mix.Tasks.Local.Rebar do
100102 true
101103 end
102104
105+ defp file_url? ( url_or_path ) do
106+ URI . parse ( url_or_path ) . scheme in [ "http" , "https" ]
107+ end
108+
103109 defp install_from_s3 ( manager , list_url , escript_url , opts ) do
104110 hex_mirror = Mix.Hex . mirror ( )
105111 list_url = hex_mirror <> list_url
@@ -114,4 +120,37 @@ defmodule Mix.Tasks.Local.Rebar do
114120
115121 install_from_path ( manager , url , Keyword . put ( opts , :sha512 , sha512 ) )
116122 end
123+
124+ defp warn_install_over_http_deprecated ( manager , url ) do
125+ shell = Mix . shell ( )
126+ basename = Path . basename ( url )
127+
128+ shell . error ( """
129+ Warning: the use of HTTP/HTTPS URLs with `mix local.rebar` is deprecated")
130+
131+ Run `mix help local.rebar` for details on installing #{ manager } from Hex's CDN.
132+ Alternatively you can fetch the file using an external HTTP client and then
133+ install it locally:
134+
135+ Unix (Linux, MacOS X):
136+
137+ $ wget #{ url }
138+ $ mix local.rebar #{ manager } #{ basename }
139+
140+ or
141+
142+ $ curl -o #{ basename } #{ url }
143+ $ mix local.rebar #{ manager } #{ basename }
144+
145+ Windows (Win7 or later):
146+
147+ > powershell -Command "Invoke-WebRequest #{ url } -OutFile #{ basename } "
148+ > mix local.rebar #{ manager } #{ basename }
149+
150+ or
151+
152+ > powershell -Command "(New-Object Net.WebClient).DownloadFile('#{ url } ', '#{ basename } ')"
153+ > mix local.rebar #{ manager } #{ basename }
154+ """ )
155+ end
117156end
0 commit comments