Class: Homebrew::UnversionedCaskChecker Private
- Inherits:
-
Object
- Object
- Homebrew::UnversionedCaskChecker
- Extended by:
- T::Sig
- Defined in:
- brew/Library/Homebrew/unversioned_cask_checker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Check unversioned casks for updates by extracting their contents and guessing the version from contained files.
Instance Attribute Summary collapse
-
#cask ⇒ Cask::Cask
readonly
private
Instance Method Summary collapse
-
#apps ⇒ Array<Cask::Artifact::App>
private
-
#guess_cask_version ⇒ String?
private
-
#initialize(cask) ⇒ void
constructor
private
-
#installer ⇒ Cask::Installer
private
-
#pkgs ⇒ Array<Cask::Artifact::Pkg>
private
-
#single_app_cask? ⇒ Boolean
private
-
#single_pkg_cask? ⇒ Boolean
private
-
#top_level_info_plists(paths) ⇒ Array<Pathname>
private
Filter paths to
Info.plist
files so that ones belonging to e.g.
Constructor Details
#initialize(cask) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 20 def initialize(cask) @cask = cask end |
Instance Attribute Details
#cask ⇒ Cask::Cask (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 17 def cask @cask end |
Instance Method Details
#apps ⇒ Array<Cask::Artifact::App>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 30 def apps @apps ||= @cask.artifacts.select { |a| a.is_a?(Cask::Artifact::App) } end |
#guess_cask_version ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 64 def guess_cask_version if apps.empty? && pkgs.empty? opoo "Cask #{cask} does not contain any apps or PKG installers." return end Dir.mktmpdir do |dir| dir = Pathname(dir) installer.yield_self do |i| i.extract_primary_container(to: dir) rescue ErrorDuringExecution => e onoe e return nil end info_plist_paths = apps.flat_map do |app| top_level_info_plists(Pathname.glob(dir/"**"/app.source.basename/"Contents"/"Info.plist")).sort end info_plist_paths.each do |info_plist_path| if (version = BundleVersion.from_info_plist(info_plist_path)) return version.nice_version end end pkg_paths = pkgs.flat_map do |pkg| Pathname.glob(dir/"**"/pkg.path.basename).sort end pkg_paths.each do |pkg_path| packages = system_command!("installer", args: ["-plist", "-pkginfo", "-pkg", pkg_path]) .plist .map { |package| package.fetch("Package") } Dir.mktmpdir do |extract_dir| extract_dir = Pathname(extract_dir) FileUtils.rmdir extract_dir begin system_command! "pkgutil", args: ["--expand-full", pkg_path, extract_dir] rescue ErrorDuringExecution => e onoe "Failed to extract #{pkg_path.basename}: #{e}" next end top_level_info_plist_paths = top_level_info_plists(Pathname.glob(extract_dir/"**/Contents/Info.plist")) unique_info_plist_versions = top_level_info_plist_paths.map { |i| BundleVersion.from_info_plist(i)&.nice_version } .compact.uniq return unique_info_plist_versions.first if unique_info_plist_versions.count == 1 package_info_path = extract_dir/"PackageInfo" if package_info_path.exist? if (version = BundleVersion.from_package_info(package_info_path)) return version.nice_version end elsif packages.count == 1 onoe "#{pkg_path.basename} does not contain a `PackageInfo` file." end distribution_path = extract_dir/"Distribution" if distribution_path.exist? Homebrew.install_bundler_gems! require "nokogiri" xml = Nokogiri::XML(distribution_path.read) product_version = xml.xpath("//installer-gui-script//product").first&.attr("version") return product_version if product_version end opoo "#{pkg_path.basename} contains multiple packages: #{packages}" if packages.count != 1 $stderr.puts Pathname.glob(extract_dir/"**/*") .map { |path| regex = %r{\A(.*?\.(app|qlgenerator|saver|plugin|kext|bundle|osax))/.*\Z} path.to_s.sub(regex, '\1') }.uniq ensure Cask::Utils.(extract_dir) extract_dir.mkpath end end nil end end |
#installer ⇒ Cask::Installer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 25 def installer @installer ||= Cask::Installer.new(cask, verify_download_integrity: false) end |
#pkgs ⇒ Array<Cask::Artifact::Pkg>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 35 def pkgs @pkgs ||= @cask.artifacts.select { |a| a.is_a?(Cask::Artifact::Pkg) } end |
#single_app_cask? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 40 def single_app_cask? apps.count == 1 end |
#single_pkg_cask? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 45 def single_pkg_cask? pkgs.count == 1 end |
#top_level_info_plists(paths) ⇒ Array<Pathname>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filter paths to Info.plist
files so that ones belonging
to e.g. nested .app
s are ignored.
52 53 54 55 56 57 58 59 60 61 |
# File 'brew/Library/Homebrew/unversioned_cask_checker.rb', line 52 def top_level_info_plists(paths) # Go from `./Contents/Info.plist` to `./`. top_level_paths = paths.map { |path| path.parent.parent } paths.reject do |path| top_level_paths.any? do |_other_top_level_path| path.ascend.drop(3).any? { |parent_path| top_level_paths.include?(parent_path) } end end end |