Refactor Cask Artifacts.
This commit is contained in:
parent
33fa80944e
commit
e1ea7bb721
@ -27,10 +27,6 @@ module Hbc
|
|||||||
|
|
||||||
attr_reader :force
|
attr_reader :force
|
||||||
|
|
||||||
def zap_phase
|
|
||||||
odebug "Nothing to do. The #{self.class.artifact_name} artifact has no zap phase."
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: this sort of logic would make more sense in dsl.rb, or a
|
# TODO: this sort of logic would make more sense in dsl.rb, or a
|
||||||
# constructor called from dsl.rb, so long as that isn't slow.
|
# constructor called from dsl.rb, so long as that isn't slow.
|
||||||
def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil)
|
def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil)
|
||||||
|
|||||||
@ -3,16 +3,6 @@ require "hbc/artifact/base"
|
|||||||
module Hbc
|
module Hbc
|
||||||
module Artifact
|
module Artifact
|
||||||
class Installer < Base
|
class Installer < Base
|
||||||
# TODO: for backward compatibility, removeme
|
|
||||||
def install
|
|
||||||
install_phase
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: for backward compatibility, removeme
|
|
||||||
def uninstall
|
|
||||||
uninstall_phase
|
|
||||||
end
|
|
||||||
|
|
||||||
def install_phase
|
def install_phase
|
||||||
@cask.artifacts[self.class.artifact_dsl_key].each do |artifact|
|
@cask.artifacts[self.class.artifact_dsl_key].each do |artifact|
|
||||||
if artifact.manual
|
if artifact.manual
|
||||||
@ -36,10 +26,6 @@ module Hbc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def uninstall_phase
|
|
||||||
odebug "Nothing to do. The #{self.class.artifact_dsl_key} artifact has no uninstall phase."
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,10 +7,6 @@ module Hbc
|
|||||||
@cask.artifacts[:nested_container].each { |container| extract(container) }
|
@cask.artifacts[:nested_container].each { |container| extract(container) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def uninstall_phase
|
|
||||||
# no need to take action; is removed after extraction
|
|
||||||
end
|
|
||||||
|
|
||||||
def extract(container_relative_path)
|
def extract(container_relative_path)
|
||||||
source = @cask.staged_path.join(container_relative_path)
|
source = @cask.staged_path.join(container_relative_path)
|
||||||
container = Container.for_path(source, @command)
|
container = Container.for_path(source, @command)
|
||||||
|
|||||||
@ -36,10 +36,6 @@ module Hbc
|
|||||||
@cask.artifacts[:pkg].each { |pkg_description| run_installer(pkg_description) }
|
@cask.artifacts[:pkg].each { |pkg_description| run_installer(pkg_description) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def uninstall_phase
|
|
||||||
# Do nothing. Must be handled explicitly by a separate :uninstall stanza.
|
|
||||||
end
|
|
||||||
|
|
||||||
def run_installer(pkg_description)
|
def run_installer(pkg_description)
|
||||||
load_pkg_description pkg_description
|
load_pkg_description pkg_description
|
||||||
ohai "Running installer for #{@cask}; your password may be necessary."
|
ohai "Running installer for #{@cask}; your password may be necessary."
|
||||||
|
|||||||
@ -6,14 +6,6 @@ module Hbc
|
|||||||
def self.artifact_dsl_key
|
def self.artifact_dsl_key
|
||||||
:stage_only
|
:stage_only
|
||||||
end
|
end
|
||||||
|
|
||||||
def install_phase
|
|
||||||
# do nothing
|
|
||||||
end
|
|
||||||
|
|
||||||
def uninstall_phase
|
|
||||||
# do nothing
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -54,15 +54,11 @@ module Hbc
|
|||||||
path_strings - undeletable
|
path_strings - undeletable
|
||||||
end
|
end
|
||||||
|
|
||||||
def install_phase
|
|
||||||
odebug "Nothing to do. The uninstall artifact has no install phase."
|
|
||||||
end
|
|
||||||
|
|
||||||
def uninstall_phase
|
def uninstall_phase
|
||||||
dispatch_uninstall_directives
|
dispatch_uninstall_directives
|
||||||
end
|
end
|
||||||
|
|
||||||
def dispatch_uninstall_directives(expand_tilde = true)
|
def dispatch_uninstall_directives(expand_tilde: true)
|
||||||
directives_set = @cask.artifacts[stanza]
|
directives_set = @cask.artifacts[stanza]
|
||||||
ohai "Running #{stanza} process for #{@cask}; your password may be necessary"
|
ohai "Running #{stanza} process for #{@cask}; your password may be necessary"
|
||||||
|
|
||||||
|
|||||||
@ -3,17 +3,8 @@ require "hbc/artifact/uninstall_base"
|
|||||||
module Hbc
|
module Hbc
|
||||||
module Artifact
|
module Artifact
|
||||||
class Zap < UninstallBase
|
class Zap < UninstallBase
|
||||||
def install_phase
|
|
||||||
odebug "Nothing to do. The zap artifact has no install phase."
|
|
||||||
end
|
|
||||||
|
|
||||||
def uninstall_phase
|
def uninstall_phase
|
||||||
odebug "Nothing to do. The zap artifact has no uninstall phase."
|
dispatch_uninstall_directives(expand_tilde: true)
|
||||||
end
|
|
||||||
|
|
||||||
def zap_phase
|
|
||||||
expand_tilde = true
|
|
||||||
dispatch_uninstall_directives(expand_tilde)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -140,15 +140,18 @@ module Hbc
|
|||||||
odebug "#{artifacts.length} artifact/s defined", artifacts
|
odebug "#{artifacts.length} artifact/s defined", artifacts
|
||||||
|
|
||||||
artifacts.each do |artifact|
|
artifacts.each do |artifact|
|
||||||
|
artifact = artifact.new(@cask, options)
|
||||||
|
next unless artifact.respond_to?(:install_phase)
|
||||||
odebug "Installing artifact of class #{artifact}"
|
odebug "Installing artifact of class #{artifact}"
|
||||||
artifact.new(@cask, options).install_phase
|
artifact.install_phase
|
||||||
already_installed_artifacts.unshift(artifact)
|
already_installed_artifacts.unshift(artifact)
|
||||||
end
|
end
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
begin
|
begin
|
||||||
already_installed_artifacts.each do |artifact|
|
already_installed_artifacts.each do |artifact|
|
||||||
|
next unless artifact.respond_to?(:uninstall_phase)
|
||||||
odebug "Reverting installation of artifact of class #{artifact}"
|
odebug "Reverting installation of artifact of class #{artifact}"
|
||||||
artifact.new(@cask, options).uninstall_phase
|
artifact.uninstall_phase
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
purge_versioned_files
|
purge_versioned_files
|
||||||
@ -319,9 +322,11 @@ module Hbc
|
|||||||
artifacts = Artifact.for_cask(@cask)
|
artifacts = Artifact.for_cask(@cask)
|
||||||
odebug "#{artifacts.length} artifact/s defined", artifacts
|
odebug "#{artifacts.length} artifact/s defined", artifacts
|
||||||
artifacts.each do |artifact|
|
artifacts.each do |artifact|
|
||||||
odebug "Un-installing artifact of class #{artifact}"
|
|
||||||
options = { command: @command, force: force }
|
options = { command: @command, force: force }
|
||||||
artifact.new(@cask, options).uninstall_phase
|
artifact = artifact.new(@cask, options)
|
||||||
|
next unless artifact.respond_to?(:uninstall_phase)
|
||||||
|
odebug "Un-installing artifact of class #{artifact}"
|
||||||
|
artifact.uninstall_phase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -330,7 +335,7 @@ module Hbc
|
|||||||
uninstall_artifacts
|
uninstall_artifacts
|
||||||
if Artifact::Zap.me?(@cask)
|
if Artifact::Zap.me?(@cask)
|
||||||
ohai "Dispatching zap stanza"
|
ohai "Dispatching zap stanza"
|
||||||
Artifact::Zap.new(@cask, command: @command).zap_phase
|
Artifact::Zap.new(@cask, command: @command).uninstall_phase
|
||||||
else
|
else
|
||||||
opoo "No zap stanza present for Cask '#{@cask}'"
|
opoo "No zap stanza present for Cask '#{@cask}'"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,16 +21,6 @@ describe Hbc::Artifact::Pkg do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "uninstall_phase" do
|
|
||||||
it "does nothing, because the uninstall_phase method is a no-op" do
|
|
||||||
pkg = Hbc::Artifact::Pkg.new(@cask,
|
|
||||||
command: Hbc::FakeSystemCommand)
|
|
||||||
shutup do
|
|
||||||
pkg.uninstall_phase
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "choices" do
|
describe "choices" do
|
||||||
before do
|
before do
|
||||||
@cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb")
|
@cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb")
|
||||||
|
|||||||
@ -13,28 +13,12 @@ describe Hbc::Artifact::Uninstall do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "install_phase" do
|
|
||||||
it "does nothing, because the install_phase method is a no-op" do
|
|
||||||
shutup do
|
|
||||||
uninstall_artifact.install_phase
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "zap_phase" do
|
|
||||||
it "does nothing, because the zap_phase method is a no-op" do
|
|
||||||
shutup do
|
|
||||||
uninstall_artifact.zap_phase
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "uninstall_phase" do
|
describe "uninstall_phase" do
|
||||||
subject do
|
subject {
|
||||||
shutup do
|
shutup do
|
||||||
uninstall_artifact.uninstall_phase
|
uninstall_artifact.uninstall_phase
|
||||||
end
|
end
|
||||||
end
|
}
|
||||||
|
|
||||||
describe "when using launchctl" do
|
describe "when using launchctl" do
|
||||||
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-launchctl.rb") }
|
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-launchctl.rb") }
|
||||||
|
|||||||
@ -14,28 +14,12 @@ describe Hbc::Artifact::Zap do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "install_phase" do
|
|
||||||
it "does nothing, because the install_phase method is a no-op" do
|
|
||||||
shutup do
|
|
||||||
zap_artifact.install_phase
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "uninstall_phase" do
|
describe "uninstall_phase" do
|
||||||
it "does nothing, because the uninstall_phase method is a no-op" do
|
subject {
|
||||||
shutup do
|
shutup do
|
||||||
zap_artifact.uninstall_phase
|
zap_artifact.uninstall_phase
|
||||||
end
|
end
|
||||||
end
|
}
|
||||||
end
|
|
||||||
|
|
||||||
describe "zap_phase" do
|
|
||||||
subject do
|
|
||||||
shutup do
|
|
||||||
zap_artifact.zap_phase
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "when using launchctl" do
|
describe "when using launchctl" do
|
||||||
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-launchctl.rb") }
|
let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-zap-launchctl.rb") }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user