Add msi DSL to query under the gems directory

parent 22afb5e6
......@@ -14,6 +14,8 @@
# limitations under the License.
#
require 'pathname'
module Omnibus
class Packager::MSI < Packager::Base
DEFAULT_TIMESTAMP_SERVERS = ['http://timestamp.digicert.com',
......@@ -311,6 +313,37 @@ module Omnibus
end
expose :signing_identity
#
# Discovers a path to a gem/file included in a gem under the install directory.
#
# @example
# gem_path 'chef-[0-9]*-mingw32' -> 'some/path/to/gems/chef-version-mingw32'
#
# @param [String] glob
# a ruby acceptable glob path such as with **, *, [] etc.
#
# @return [String] path relative to the project's install_dir
#
# Raises exception the glob matches 0 or more than 1 file/directory.
#
def gem_path(glob = NULL)
unless glob.is_a?(String) || null?(glob)
raise InvalidValue.new(:glob, 'be an String')
end
install_path = Pathname.new(project.install_dir)
# Find path in which the Chef gem is installed
search_pattern = install_path.join('**', 'gems')
search_pattern = search_pattern.join(glob) unless null?(glob)
file_paths = Pathname.glob(search_pattern).find
raise "Could not find `#{search_pattern}'!" if file_paths.none?
raise "Multiple possible matches of `#{search_pattern}'! : #{file_paths}" if file_paths.count > 1
file_paths.first.relative_path_from(install_path).to_s
end
expose :gem_path
#
# @!endgroup
# --------------------------------------------------
......
......@@ -6,7 +6,7 @@ module Omnibus
Project.new.tap do |project|
project.name('project')
project.homepage('https://example.com')
project.install_dir('C:/project')
project.install_dir(install_dir)
project.build_version('1.2.3')
project.build_iteration('2')
project.maintainer('Chef Software <maintainers@chef.io>')
......@@ -18,6 +18,7 @@ module Omnibus
let(:project_root) { File.join(tmp_path, 'project/root') }
let(:package_dir) { File.join(tmp_path, 'package/dir') }
let(:staging_dir) { File.join(tmp_path, 'staging/dir') }
let(:install_dir) { 'C:/project' }
before do
Config.project_root(project_root)
......@@ -298,7 +299,7 @@ module Omnibus
end
end
describe "#bundle_msi" do
describe '#bundle_msi' do
it 'is a DSL method' do
expect(subject).to have_exposed_method(:bundle_msi)
end
......@@ -315,6 +316,40 @@ module Omnibus
end
end
describe '#gem_path' do
let(:install_dir) { File.join(tmp_path, 'install_dir') }
before do
create_directory(install_dir)
end
after do
remove_directory(install_dir)
end
it 'is a DSL method' do
expect(subject).to have_exposed_method(:gem_path)
end
it 'requires the value to be a String' do
expect {
subject.gem_path(Object.new)
}.to raise_error(InvalidValue)
end
it 'globs for gems under the install directory' do
expected_gem_path = 'something/gems/athing-1.0.0'
create_directory(File.join(install_dir, expected_gem_path))
expect(subject.gem_path('athing-*')).to eq(expected_gem_path)
end
it 'returns the gem directory when no argument is given' do
expected_gem_path = 'foo/bar123/gems'
create_directory(File.join(install_dir, expected_gem_path))
expect(subject.gem_path).to eq(expected_gem_path)
end
end
context 'when signing parameters are provided' do
let(:msi) { 'somemsi.msi' }
......@@ -343,7 +378,7 @@ module Omnibus
subject.sign_package(msi)
end
describe "#timestamp_servers" do
describe '#timestamp_servers' do
it "defaults to using ['http://timestamp.digicert.com','http://timestamp.verisign.com/scripts/timestamp.dll']" do
subject.signing_identity('foo')
expect(subject).to receive(:try_timestamp).with(msi, 'http://timestamp.digicert.com').and_return(false)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment