Replace Utils::JSON with corelib JSON calls.
This commit is contained in:
parent
54d18cee17
commit
d07b9ed7f2
@ -22,7 +22,7 @@ require "options"
|
|||||||
require "formula"
|
require "formula"
|
||||||
require "keg"
|
require "keg"
|
||||||
require "tab"
|
require "tab"
|
||||||
require "utils/json"
|
require "json"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
@ -72,7 +72,7 @@ module Homebrew
|
|||||||
ARGV.formulae
|
ARGV.formulae
|
||||||
end
|
end
|
||||||
json = ff.map(&:to_hash)
|
json = ff.map(&:to_hash)
|
||||||
puts Utils::JSON.dump(json)
|
puts JSON.generate(json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_remote_path(remote, path)
|
def github_remote_path(remote, path)
|
||||||
|
@ -88,7 +88,7 @@ module Homebrew
|
|||||||
installed_versions: outdated_versions.collect(&:to_s),
|
installed_versions: outdated_versions.collect(&:to_s),
|
||||||
current_version: current_version }
|
current_version: current_version }
|
||||||
end
|
end
|
||||||
puts Utils::JSON.dump(json)
|
puts JSON.generate(json)
|
||||||
|
|
||||||
outdated
|
outdated
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#: Exits with a non-zero status if any style violations are found.
|
#: Exits with a non-zero status if any style violations are found.
|
||||||
|
|
||||||
require "utils"
|
require "utils"
|
||||||
require "utils/json"
|
require "json"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
@ -74,7 +74,7 @@ module Homebrew
|
|||||||
# exitstatus can also be nil if RuboCop process crashes, e.g. due to
|
# exitstatus can also be nil if RuboCop process crashes, e.g. due to
|
||||||
# native extension problems
|
# native extension problems
|
||||||
raise "Error while running RuboCop" if $?.exitstatus.nil? || $?.exitstatus > 1
|
raise "Error while running RuboCop" if $?.exitstatus.nil? || $?.exitstatus > 1
|
||||||
RubocopResults.new(Utils::JSON.load(json))
|
RubocopResults.new(JSON.parse(json))
|
||||||
else
|
else
|
||||||
raise "Invalid output_type for check_style_impl: #{output_type}"
|
raise "Invalid output_type for check_style_impl: #{output_type}"
|
||||||
end
|
end
|
||||||
|
@ -82,6 +82,6 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def print_tap_json(taps)
|
def print_tap_json(taps)
|
||||||
puts Utils::JSON.dump(taps.map(&:to_hash))
|
puts JSON.generate(taps.map(&:to_hash))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,14 +12,14 @@ class Descriptions
|
|||||||
# If the cache file exists, load it into, and return, a hash; otherwise,
|
# If the cache file exists, load it into, and return, a hash; otherwise,
|
||||||
# return nil.
|
# return nil.
|
||||||
def self.load_cache
|
def self.load_cache
|
||||||
@cache = Utils::JSON.load(CACHE_FILE.read) if CACHE_FILE.exist?
|
@cache = JSON.parse(CACHE_FILE.read) if CACHE_FILE.exist?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write the cache to disk after ensuring the existence of the containing
|
# Write the cache to disk after ensuring the existence of the containing
|
||||||
# directory.
|
# directory.
|
||||||
def self.save_cache
|
def self.save_cache
|
||||||
HOMEBREW_CACHE.mkpath
|
HOMEBREW_CACHE.mkpath
|
||||||
CACHE_FILE.atomic_write Utils::JSON.dump(@cache)
|
CACHE_FILE.atomic_write JSON.dump(@cache)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a hash mapping all formulae to their descriptions;
|
# Create a hash mapping all formulae to their descriptions;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#: If `--reason=<reason>` is passed, append this to the commit/PR message.
|
#: If `--reason=<reason>` is passed, append this to the commit/PR message.
|
||||||
|
|
||||||
require "formula"
|
require "formula"
|
||||||
require "utils/json"
|
require "json"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -60,7 +60,7 @@ module Homebrew
|
|||||||
EOS
|
EOS
|
||||||
safe_system "git", "add", tap_migrations_path
|
safe_system "git", "add", tap_migrations_path
|
||||||
end
|
end
|
||||||
tap_migrations = Utils::JSON.load(File.read(tap_migrations_path))
|
tap_migrations = JSON.parse(File.read(tap_migrations_path))
|
||||||
tap_migrations[formula.name] = boneyard_tap.name
|
tap_migrations[formula.name] = boneyard_tap.name
|
||||||
tap_migrations = tap_migrations.sort.inject({}) { |acc, elem| acc.merge!(elem[0] => elem[1]) }
|
tap_migrations = tap_migrations.sort.inject({}) { |acc, elem| acc.merge!(elem[0] => elem[1]) }
|
||||||
tap_migrations_path.atomic_write(JSON.pretty_generate(tap_migrations) + "\n")
|
tap_migrations_path.atomic_write(JSON.pretty_generate(tap_migrations) + "\n")
|
||||||
|
@ -344,7 +344,7 @@ module Homebrew
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
File.open("#{filename.prefix}.bottle.json", "w") do |file|
|
File.open("#{filename.prefix}.bottle.json", "w") do |file|
|
||||||
file.write Utils::JSON.dump json
|
file.write JSON.generate json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -352,7 +352,7 @@ module Homebrew
|
|||||||
write = ARGV.include? "--write"
|
write = ARGV.include? "--write"
|
||||||
|
|
||||||
bottles_hash = ARGV.named.reduce({}) do |hash, json_file|
|
bottles_hash = ARGV.named.reduce({}) do |hash, json_file|
|
||||||
deep_merge_hashes hash, Utils::JSON.load(IO.read(json_file))
|
deep_merge_hashes hash, JSON.parse(IO.read(json_file))
|
||||||
end
|
end
|
||||||
|
|
||||||
bottles_hash.each do |formula_name, bottle_hash|
|
bottles_hash.each do |formula_name, bottle_hash|
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
require "net/http"
|
require "net/http"
|
||||||
require "net/https"
|
require "net/https"
|
||||||
require "utils"
|
require "utils"
|
||||||
require "utils/json"
|
require "json"
|
||||||
require "formula"
|
require "formula"
|
||||||
require "formulary"
|
require "formulary"
|
||||||
require "tap"
|
require "tap"
|
||||||
@ -433,7 +433,7 @@ module Homebrew
|
|||||||
return nil unless $?.success?
|
return nil unless $?.success?
|
||||||
|
|
||||||
Homebrew.force_utf8!(json)
|
Homebrew.force_utf8!(json)
|
||||||
FormulaInfoFromJson.new(Utils::JSON.load(json)[0])
|
FormulaInfoFromJson.new(JSON.parse(json)[0])
|
||||||
end
|
end
|
||||||
|
|
||||||
def bottle_tags
|
def bottle_tags
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
require "utils/json"
|
require "json"
|
||||||
require "rexml/document"
|
require "rexml/document"
|
||||||
require "time"
|
require "time"
|
||||||
|
|
||||||
@ -444,14 +444,14 @@ class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
|
|||||||
return super if @tried_apache_mirror
|
return super if @tried_apache_mirror
|
||||||
@tried_apache_mirror = true
|
@tried_apache_mirror = true
|
||||||
|
|
||||||
mirrors = Utils::JSON.load(apache_mirrors)
|
mirrors = JSON.parse(apache_mirrors)
|
||||||
path_info = mirrors.fetch("path_info")
|
path_info = mirrors.fetch("path_info")
|
||||||
@url = mirrors.fetch("preferred") + path_info
|
@url = mirrors.fetch("preferred") + path_info
|
||||||
@mirrors |= %W[https://archive.apache.org/dist/#{path_info}]
|
@mirrors |= %W[https://archive.apache.org/dist/#{path_info}]
|
||||||
|
|
||||||
ohai "Best Mirror #{@url}"
|
ohai "Best Mirror #{@url}"
|
||||||
super
|
super
|
||||||
rescue IndexError, Utils::JSON::Error
|
rescue IndexError, JSON::ParserError
|
||||||
raise CurlDownloadStrategyError, "Couldn't determine mirror, try again later."
|
raise CurlDownloadStrategyError, "Couldn't determine mirror, try again later."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require "cxxstdlib"
|
require "cxxstdlib"
|
||||||
require "ostruct"
|
require "ostruct"
|
||||||
require "options"
|
require "options"
|
||||||
require "utils/json"
|
require "json"
|
||||||
require "development_tools"
|
require "development_tools"
|
||||||
|
|
||||||
# Inherit from OpenStruct to gain a generic initialization method that takes a
|
# Inherit from OpenStruct to gain a generic initialization method that takes a
|
||||||
@ -58,7 +58,7 @@ class Tab < OpenStruct
|
|||||||
|
|
||||||
# Like Tab.from_file, but bypass the cache.
|
# Like Tab.from_file, but bypass the cache.
|
||||||
def self.from_file_content(content, path)
|
def self.from_file_content(content, path)
|
||||||
attributes = Utils::JSON.load(content)
|
attributes = JSON.parse(content)
|
||||||
attributes["tabfile"] = path
|
attributes["tabfile"] = path
|
||||||
attributes["source_modified_time"] ||= 0
|
attributes["source_modified_time"] ||= 0
|
||||||
attributes["source"] ||= {}
|
attributes["source"] ||= {}
|
||||||
@ -313,7 +313,7 @@ class Tab < OpenStruct
|
|||||||
"source" => source,
|
"source" => source,
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::JSON.dump(attributes)
|
JSON.generate(attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def write
|
def write
|
||||||
|
@ -442,10 +442,10 @@ class Tap
|
|||||||
|
|
||||||
# Hash with tap formula renames
|
# Hash with tap formula renames
|
||||||
def formula_renames
|
def formula_renames
|
||||||
require "utils/json"
|
require "json"
|
||||||
|
|
||||||
@formula_renames ||= if (rename_file = path/"formula_renames.json").file?
|
@formula_renames ||= if (rename_file = path/"formula_renames.json").file?
|
||||||
Utils::JSON.load(rename_file.read)
|
JSON.parse(rename_file.read)
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
@ -453,10 +453,10 @@ class Tap
|
|||||||
|
|
||||||
# Hash with tap migrations
|
# Hash with tap migrations
|
||||||
def tap_migrations
|
def tap_migrations
|
||||||
require "utils/json"
|
require "json"
|
||||||
|
|
||||||
@tap_migrations ||= if (migration_file = path/"tap_migrations.json").file?
|
@tap_migrations ||= if (migration_file = path/"tap_migrations.json").file?
|
||||||
Utils::JSON.load(migration_file.read)
|
JSON.parse(migration_file.read)
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
require "testing_env"
|
require "testing_env"
|
||||||
require "utils/json"
|
require "json"
|
||||||
|
|
||||||
class JsonSmokeTest < Homebrew::TestCase
|
class JsonSmokeTest < Homebrew::TestCase
|
||||||
def test_encode
|
def test_encode
|
||||||
hash = { "foo" => ["bar", "baz"] }
|
hash = { "foo" => ["bar", "baz"] }
|
||||||
json = '{"foo":["bar","baz"]}'
|
json = '{"foo":["bar","baz"]}'
|
||||||
assert_equal json, Utils::JSON.dump(hash)
|
assert_equal json, JSON.generate(hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_decode
|
def test_decode
|
||||||
hash = { "foo" => ["bar", "baz"], "qux" => 1 }
|
hash = { "foo" => ["bar", "baz"], "qux" => 1 }
|
||||||
json = '{"foo":["bar","baz"],"qux":1}'
|
json = '{"foo":["bar","baz"],"qux":1}'
|
||||||
assert_equal hash, Utils::JSON.load(json)
|
assert_equal hash, JSON.parse(json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_decode_failure
|
def test_decode_failure
|
||||||
assert_raises(Utils::JSON::Error) { Utils::JSON.load("nope") }
|
assert_raises(JSON::ParserError) { JSON.parse("nope") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -185,7 +185,7 @@ class IntegrationCommandTestCase < Homebrew::TestCase
|
|||||||
cmd("install", old_name)
|
cmd("install", old_name)
|
||||||
(core_tap.path/"Formula/#{old_name}.rb").unlink
|
(core_tap.path/"Formula/#{old_name}.rb").unlink
|
||||||
formula_renames = core_tap.path/"formula_renames.json"
|
formula_renames = core_tap.path/"formula_renames.json"
|
||||||
formula_renames.write Utils::JSON.dump(old_name => new_name)
|
formula_renames.write JSON.generate(old_name => new_name)
|
||||||
|
|
||||||
core_tap.path.cd do
|
core_tap.path.cd do
|
||||||
shutup do
|
shutup do
|
||||||
|
@ -186,7 +186,7 @@ class TabTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_to_json
|
def test_to_json
|
||||||
tab = Tab.new(Utils::JSON.load(@tab.to_json))
|
tab = Tab.new(JSON.parse(@tab.to_json))
|
||||||
assert_equal @tab.used_options.sort, tab.used_options.sort
|
assert_equal @tab.used_options.sort, tab.used_options.sort
|
||||||
assert_equal @tab.unused_options.sort, tab.unused_options.sort
|
assert_equal @tab.unused_options.sort, tab.unused_options.sort
|
||||||
assert_equal @tab.built_as_bottle, tab.built_as_bottle
|
assert_equal @tab.built_as_bottle, tab.built_as_bottle
|
||||||
|
@ -149,9 +149,9 @@ module GitHub
|
|||||||
data_tmpfile = nil
|
data_tmpfile = nil
|
||||||
if data
|
if data
|
||||||
begin
|
begin
|
||||||
data = Utils::JSON.dump data
|
data = JSON.generate data
|
||||||
data_tmpfile = Tempfile.new("github_api_post", HOMEBREW_TEMP)
|
data_tmpfile = Tempfile.new("github_api_post", HOMEBREW_TEMP)
|
||||||
rescue Utils::JSON::Error => e
|
rescue JSON::ParserError => e
|
||||||
raise Error, "Failed to parse JSON request:\n#{e.message}\n#{data}", e.backtrace
|
raise Error, "Failed to parse JSON request:\n#{e.message}\n#{data}", e.backtrace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -183,13 +183,13 @@ module GitHub
|
|||||||
if !http_code.start_with?("2") && !status.success?
|
if !http_code.start_with?("2") && !status.success?
|
||||||
raise_api_error(output, errors, http_code, headers, scopes)
|
raise_api_error(output, errors, http_code, headers, scopes)
|
||||||
end
|
end
|
||||||
json = Utils::JSON.load output
|
json = JSON.parse output
|
||||||
if block_given?
|
if block_given?
|
||||||
yield json
|
yield json
|
||||||
else
|
else
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
rescue Utils::JSON::Error => e
|
rescue JSON::ParserError => e
|
||||||
raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace
|
raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -205,7 +205,7 @@ module GitHub
|
|||||||
|
|
||||||
if meta.fetch("x-ratelimit-remaining", 1).to_i <= 0
|
if meta.fetch("x-ratelimit-remaining", 1).to_i <= 0
|
||||||
reset = meta.fetch("x-ratelimit-reset").to_i
|
reset = meta.fetch("x-ratelimit-reset").to_i
|
||||||
error = Utils::JSON.load(output)["message"]
|
error = JSON.parse(output)["message"]
|
||||||
raise RateLimitExceededError.new(reset, error)
|
raise RateLimitExceededError.new(reset, error)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ module GitHub
|
|||||||
raise HTTPNotFoundError, output
|
raise HTTPNotFoundError, output
|
||||||
else
|
else
|
||||||
error = begin
|
error = begin
|
||||||
Utils::JSON.load(output)["message"]
|
JSON.parse(output)["message"]
|
||||||
rescue
|
rescue
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user