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