Skip to content

Commit

Permalink
Merge remote branch 'gaffneyc/master'.
Browse files Browse the repository at this point in the history
Updated other merged installer definitions to support multiple installers, and fixed metapackage definition check.

Conflicts:
	.gitignore
  • Loading branch information
crafterm committed Dec 11, 2009
2 parents c38747e + 89a7875 commit 337ea40
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
pkg
.DS_Store
.idea
.*.swp
45 changes: 24 additions & 21 deletions lib/sprinkle/package.rb
Expand Up @@ -107,7 +107,7 @@ def package(name, metadata = {}, &block)

class Package #:nodoc:
include ArbitraryOptions
attr_accessor :name, :provides, :installer, :dependencies, :recommends, :verifications
attr_accessor :name, :provides, :installers, :dependencies, :recommends, :verifications

def initialize(name, metadata = {}, &block)
raise 'No package name supplied' unless name
Expand All @@ -118,73 +118,74 @@ def initialize(name, metadata = {}, &block)
@recommends = []
@optional = []
@verifications = []
@installers = []
self.instance_eval &block
end

def freebsd_pkg(*names, &block)
@installer = Sprinkle::Installers::FreebsdPkg.new(self, *names, &block)
@installers << Sprinkle::Installers::FreebsdPkg.new(self, *names, &block)
end

def openbsd_pkg(*names, &block)
@installer = Sprinkle::Installers::OpenbsdPkg.new(self, *names, &block)
@installers << Sprinkle::Installers::OpenbsdPkg.new(self, *names, &block)
end

def opensolaris_pkg(*names, &block)
@installer = Sprinkle::Installers::OpensolarisPkg.new(self, *names, &block)
@installers << Sprinkle::Installers::OpensolarisPkg.new(self, *names, &block)
end

def bsd_port(port, &block)
@installer = Sprinkle::Installers::BsdPort.new(self, port, &block)
@installers << Sprinkle::Installers::BsdPort.new(self, port, &block)
end

def mac_port(port, &block)
@installer = Sprinkle::Installers::MacPort.new(self, port, &block)
@installers << Sprinkle::Installers::MacPort.new(self, port, &block)
end

def apt(*names, &block)
@installer = Sprinkle::Installers::Apt.new(self, *names, &block)
@installers << Sprinkle::Installers::Apt.new(self, *names, &block)
end

def deb(*names, &block)
@installer = Sprinkle::Installers::Deb.new(self, *names, &block)
@installers << Sprinkle::Installers::Deb.new(self, *names, &block)
end

def rpm(*names, &block)
@installer = Sprinkle::Installers::Rpm.new(self, *names, &block)
@installers << Sprinkle::Installers::Rpm.new(self, *names, &block)
end

def yum(*names, &block)
@installer = Sprinkle::Installers::Yum.new(self, *names, &block)
@installers << Sprinkle::Installers::Yum.new(self, *names, &block)
end

def gem(name, options = {}, &block)
@recommends << :rubygems
@installer = Sprinkle::Installers::Gem.new(self, name, options, &block)
@installers << Sprinkle::Installers::Gem.new(self, name, options, &block)
end

def source(source, options = {}, &block)
@recommends << :build_essential # Ubuntu/Debian
@installer = Sprinkle::Installers::Source.new(self, source, options, &block)
@installers << Sprinkle::Installers::Source.new(self, source, options, &block)
end

def binary(source, options = {}, &block)
@installer = Sprinkle::Installers::Binary.new(self, source, options, &block)
@installers << Sprinkle::Installers::Binary.new(self, source, options, &block)
end

def rake(name, options = {}, &block)
@installer = Sprinkle::Installers::Rake.new(self, name, options, &block)
@installers << Sprinkle::Installers::Rake.new(self, name, options, &block)
end

def noop(&block)
@installer = Sprinkle::Installers::Noop.new(self, name, options, &block)
@installers << Sprinkle::Installers::Noop.new(self, name, options, &block)
end

def push_text(text, path, options = {}, &block)
@installer = Sprinkle::Installers::PushText.new(self, text, path, options, &block)
@installers << Sprinkle::Installers::PushText.new(self, text, path, options, &block)
end

def transfer(source, destination, options = {}, &block)
@installer = Sprinkle::Installers::Transfer.new(self, source, destination, options, &block)
def transfer(source, destination, options = {}, &block)
@installers << Sprinkle::Installers::Transfer.new(self, source, destination, options, &block)
end

def verify(description = '', &block)
Expand All @@ -207,8 +208,10 @@ def process(deployment, roles)
end
end

@installer.defaults(deployment)
@installer.process(roles)
@installers.each do |installer|
installer.defaults(deployment)
installer.process(roles)
end

process_verifications(deployment, roles)
end
Expand Down Expand Up @@ -295,7 +298,7 @@ def select_package(name, packages)
end

def meta_package?
@installer == nil
@installers.blank?
end
end
end
Expand Down
30 changes: 20 additions & 10 deletions spec/sprinkle/package_spec.rb
Expand Up @@ -22,7 +22,7 @@ def check_block_forwarding_on(installer)
end
end
pre_count = pkg.installer.instance_variable_get(:@pre)[:install].length
pre_count = pkg.installers.first.instance_variable_get(:@pre)[:install].length
}.should change { pre_count }.by(1)
CODE
end
Expand Down Expand Up @@ -66,7 +66,7 @@ def create_package_with_blank_verify(n = 1)
pkg = package @name do
gem 'rails'
end
pkg.installer.should_not be_nil
pkg.installers.should_not be_empty
end

it 'should optionally accept dependencies' do
Expand Down Expand Up @@ -123,33 +123,43 @@ def create_package_with_blank_verify(n = 1)
apt %w( deb1 deb2 )
end
pkg.should respond_to(:apt)
pkg.installer.class.should == Sprinkle::Installers::Apt
pkg.installers.first.class.should == Sprinkle::Installers::Apt
end

it 'should optionally accept an rpm installer' do
pkg = package @name do
rpm %w( rpm1 rpm2 )
end
pkg.should respond_to(:rpm)
pkg.installer.class.should == Sprinkle::Installers::Rpm
pkg.installers.first.class.should == Sprinkle::Installers::Rpm
end

it 'should optionally accept a gem installer' do
pkg = package @name do
gem 'gem'
end
pkg.should respond_to(:gem)
pkg.installer.class.should == Sprinkle::Installers::Gem
pkg.installers.first.class.should == Sprinkle::Installers::Gem
end

it 'should optionally accept a source installer' do
pkg = package @name do
source 'archive'
end
pkg.should respond_to(:source)
pkg.installer.class.should == Sprinkle::Installers::Source
pkg.installers.first.class.should == Sprinkle::Installers::Source
end

it 'should allow multiple installer steps to be defined and respect order' do
pkg = package @name do
source 'archive'
gem 'momoney'
end

pkg.installers.length.should == 2
pkg.installers[0].class.should == Sprinkle::Installers::Source
pkg.installers[1].class.should == Sprinkle::Installers::Gem
end
end

describe 'with a source installer' do
Expand All @@ -159,7 +169,7 @@ def create_package_with_blank_verify(n = 1)
source 'archive' do; end
end
pkg.should respond_to(:source)
pkg.installer.class.should == Sprinkle::Installers::Source
pkg.installers.first.class.should == Sprinkle::Installers::Source
end

it 'should forward block to installer superclass' do
Expand Down Expand Up @@ -214,7 +224,7 @@ def create_package_with_blank_verify(n = 1)
describe 'with an installer' do

before do
@package.installer = @installer
@package.installers = [ @installer ]
end

it 'should configure itself against the deployment context' do
Expand Down Expand Up @@ -242,7 +252,7 @@ def create_package_with_blank_verify(n = 1)
describe 'with verifications' do
before do
@pkg = create_package_with_blank_verify(3)
@pkg.installer = @installer
@pkg.installers = [ @installer ]
@installer.stub!(:defaults)
@installer.stub!(:process)
end
Expand Down Expand Up @@ -303,7 +313,7 @@ def create_package_with_blank_verify(n = 1)
@roles = [ :app, :db ]
@installer = mock(Sprinkle::Installers::Installer, :defaults => true, :process => true)
@pkg = create_package_with_blank_verify(3)
@pkg.installer = @installer
@pkg.installers = [ @installer ]
@installer.stub!(:defaults)
@installer.stub!(:process)
@logger = mock(ActiveSupport::BufferedLogger, :debug => true, :debug? => true)
Expand Down

0 comments on commit 337ea40

Please sign in to comment.