Skip to content

Commit a184b40

Browse files
author
José Valim
committed
Rename :application to Application and remove unused fixtures
1 parent f3e26c2 commit a184b40

File tree

25 files changed

+67
-103
lines changed

25 files changed

+67
-103
lines changed

lib/elixir/lib/kernel/cli.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ defmodule Kernel.CLI do
278278
end
279279

280280
defp process_command({:app, app}, _config) when is_binary(app) do
281-
case :application.ensure_all_started(binary_to_atom(app)) do
281+
case Application.ensure_all_started(binary_to_atom(app)) do
282282
{:error, {app, reason}} ->
283283
{:error, "--app : Could not start application #{app}: " <>
284284
Application.format_reason(reason)}

lib/elixir/lib/uri.ex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,20 @@ defmodule URI do
4545
4646
"""
4747
def default_port(scheme) when is_binary(scheme) do
48-
{:ok, dict} = :application.get_env(:elixir, :uri)
48+
{:ok, dict} = Application.fetch_env(:elixir, :uri)
4949
Map.get(dict, scheme)
5050
end
5151

5252
@doc """
5353
Registers a scheme with a default port.
54+
55+
It is recommended for this function to be invoked in your
56+
application start callback in case you want to register
57+
new URIs.
5458
"""
5559
def default_port(scheme, port) when is_binary(scheme) and port > 0 do
56-
{:ok, dict} = :application.get_env(:elixir, :uri)
57-
:application.set_env(:elixir, :uri, Map.put(dict, scheme, port))
60+
{:ok, dict} = Application.fetch_env(:elixir, :uri)
61+
Application.put_env(:elixir, :uri, Map.put(dict, scheme, port), persist: true)
5862
end
5963

6064
@doc """

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,20 @@ defmodule Inspect.OthersTest do
330330
end
331331
end
332332

333-
:application.set_env(:elixir, :anony, V.fun)
334-
:application.set_env(:elixir, :named, &V.fun/0)
333+
Application.put_env(:elixir, :anony, V.fun)
334+
Application.put_env(:elixir, :named, &V.fun/0)
335335

336336
:code.delete(V)
337337
:code.purge(V)
338338

339-
{:ok, anony} = :application.get_env(:elixir, :anony)
340-
{:ok, named} = :application.get_env(:elixir, :named)
339+
anony = Application.get_env(:elixir, :anony)
340+
named = Application.get_env(:elixir, :named)
341341

342342
assert inspect(anony) =~ ~r"#Function<0.\d+/0 in Inspect.OthersTest.V>"
343343
assert inspect(named) =~ ~r"&Inspect.OthersTest.V.fun/0"
344344
after
345-
:application.unset_env(:elixir, :anony)
346-
:application.unset_env(:elixir, :named)
345+
Application.delete_env(:elixir, :anony)
346+
Application.delete_env(:elixir, :named)
347347
end
348348

349349
test :other_funs do

lib/ex_unit/lib/ex_unit.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ defmodule ExUnit do
114114
If you want to run tests manually, you can set `:autorun` to `false`.
115115
"""
116116
def start(options \\ []) do
117-
:application.start(:elixir)
118-
:application.start(:ex_unit)
117+
Application.start(:elixir)
118+
Application.start(:ex_unit)
119119

120120
configure(options)
121121

122-
if :application.get_env(:ex_unit, :autorun) != {:ok, false} do
123-
:application.set_env(:ex_unit, :autorun, false)
122+
if Application.get_env(:ex_unit, :autorun, true) do
123+
Application.put_env(:ex_unit, :autorun, false)
124124

125125
System.at_exit fn
126126
0 ->

lib/iex/lib/iex/options.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ defmodule IEx.Options do
5353

5454
for key <- @supported_options do
5555
def get(unquote(key)) do
56-
{:ok, value} = :application.get_env(:iex, unquote(key))
56+
{:ok, value} = Application.fetch_env(:iex, unquote(key))
5757
value
5858
end
5959
end
@@ -102,7 +102,7 @@ defmodule IEx.Options do
102102

103103
def set(:history_size, size) when is_integer(size) do
104104
old_size = get(:history_size)
105-
:application.set_env(:iex, :history_size, size)
105+
Application.put_env(:iex, :history_size, size)
106106
old_size
107107
end
108108

lib/mix/lib/mix.ex

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ defmodule Mix do
1515

1616
@doc false
1717
def start do
18-
:application.start(:elixir)
19-
:application.start(:mix)
18+
Application.start(:elixir)
19+
Application.start(:mix)
2020
end
2121

2222
@doc false
@@ -32,11 +32,8 @@ defmodule Mix do
3232
Returns the mix environment.
3333
"""
3434
def env do
35-
# env is not available on bootstrapping
36-
case :application.get_env(:mix, :env) do
37-
{:ok, env} -> env
38-
:undefined -> :dev
39-
end
35+
# env is not available on bootstrapping, so set a :dev default
36+
Application.get_env(:mix, :env, :dev)
4037
end
4138

4239
@doc """
@@ -46,7 +43,7 @@ defmodule Mix do
4643
configuration won't be reloaded.
4744
"""
4845
def env(env) when is_atom(env) do
49-
:application.set_env(:mix, :env, env)
46+
Application.put_env(:mix, :env, env)
5047
end
5148

5249
@doc """
@@ -58,17 +55,14 @@ defmodule Mix do
5855
messages to the current process.
5956
"""
6057
def shell do
61-
case :application.get_env(:mix, :shell) do
62-
{:ok, shell} -> shell
63-
:undefined -> Mix.Shell.IO
64-
end
58+
Application.get_env(:mix, :shell, Mix.Shell.IO)
6559
end
6660

6761
@doc """
6862
Sets the current shell.
6963
"""
7064
def shell(shell) do
71-
:application.set_env(:mix, :shell, shell)
65+
Application.put_env(:mix, :shell, shell)
7266
end
7367

7468
@doc false

lib/mix/lib/mix/remote_converger.ex

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,13 @@ defmodule Mix.RemoteConverger do
3030
Get registered remote converger.
3131
"""
3232
def get do
33-
case :application.get_env(:mix, :remote_converger) do
34-
{:ok, converger} -> converger
35-
:undefined -> nil
36-
end
33+
Application.get_env(:mix, :remote_converger)
3734
end
3835

3936
@doc """
4037
Register a remote converger.
4138
"""
4239
def register(mod) when is_atom(mod) do
43-
:application.set_env(:mix, :remote_converger, mod)
40+
Application.put_env(:mix, :remote_converger, mod)
4441
end
4542
end

lib/mix/lib/mix/scm.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ defmodule Mix.SCM do
110110
until a matching one is found.
111111
"""
112112
def available do
113-
{:ok, scm} = :application.get_env(:mix, :scm)
113+
{:ok, scm} = Application.fetch_env(:mix, :scm)
114114
scm
115115
end
116116

@@ -119,14 +119,14 @@ defmodule Mix.SCM do
119119
"""
120120
def prepend(mod) when is_atom(mod) do
121121
available = Enum.reject(available(), &(&1 == mod))
122-
:application.set_env(:mix, :scm, [mod|available])
122+
Application.put_env(:mix, :scm, [mod|available])
123123
end
124124

125125
@doc """
126126
Aopend the given SCM module to the list of available SCMs.
127127
"""
128128
def append(mod) when is_atom(mod) do
129129
available = Enum.reject(available(), &(&1 == mod))
130-
:application.set_env(:mix, :scm, available ++ [mod])
130+
Application.put_env(:mix, :scm, available ++ [mod])
131131
end
132132
end

lib/mix/lib/mix/scm/git.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,17 @@ defmodule Mix.SCM.Git do
159159
end
160160

161161
defp git_version do
162-
case :application.get_env(:mix, :git_version) do
162+
case Application.fetch_env(:mix, :git_version) do
163163
{:ok, version} ->
164164
version
165-
:undefined ->
165+
:error ->
166166
"git version " <> version = String.strip System.cmd("git --version")
167167
version = String.split(version, ".")
168168
|> Enum.take(3)
169169
|> Enum.map(&binary_to_integer(&1))
170170
|> list_to_tuple
171171

172-
:application.set_env(:mix, :git_version, version)
172+
Application.put_env(:mix, :git_version, version)
173173
version
174174
end
175175
end

lib/mix/lib/mix/tasks/app.start.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule Mix.Tasks.App.Start do
3434
@doc false
3535
def start(app) do
3636
if app do
37-
case :application.ensure_all_started(app) do
37+
case Application.ensure_all_started(app) do
3838
{:ok, _} -> :ok
3939
{:error, {app, reason}} ->
4040
raise Mix.Error, message: "Could not start application #{app}: " <>

0 commit comments

Comments
 (0)