Skip to content

Commit

Permalink
Handle versions like 0.5.0-rc1
Browse files Browse the repository at this point in the history
This is ugly, but it works for now...
  • Loading branch information
dgoodlad committed Dec 4, 2012
1 parent 116e942 commit 996eb9a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 21 deletions.
12 changes: 12 additions & 0 deletions features/install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ Feature: cli/install
And the file "modules/apt/Modulefile" should match /version *'1\.0\.0'/
And the file "modules/stdlib/Modulefile" should match /name *'puppetlabs-stdlib'/

Scenario: Installing a module with a '-rc' suffix
Given a file named "Puppetfile" with:
"""
forge "http://forge.puppetlabs.com"
mod 'puppetlabs/apache', '0.5.0-rc1'
"""
When I run `librarian-puppet install`
Then the exit status should be 0
And the file "modules/apache/Modulefile" should match /name *'puppetlabs-apache'/
And the file "modules/apache/Modulefile" should match /version *'0\.5\.0-rc1'/

Scenario: Changing the path
Given a directory named "puppet"
And a file named "Puppetfile" with:
Expand Down
2 changes: 1 addition & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
slow_boot ||= RUBY_PLATFORM == "java"
slow_boot ||= defined?(::Rubinius)

@aruba_timeout_seconds = slow_boot ? 30 : 2
@aruba_timeout_seconds = slow_boot ? 60 : 2
end
33 changes: 15 additions & 18 deletions lib/librarian/puppet/extension.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'librarian/puppet/environment'
require 'librarian/puppet/version_mapper'

module Librarian
module Puppet
Expand All @@ -13,28 +14,24 @@ class Dependency
class Requirement
def initialize(*args)
args = initialize_normalize_args(args)
self.backing = Gem::Requirement.create(puppet_to_gem_versions(args))
versions = Librarian::Puppet::VersionMapper.new.puppet_to_gem_versions(args)
self.backing = Gem::Requirement.create(versions)
end
end
end
end

def puppet_to_gem_versions(args)
args.map do |arg|
case arg
when Array
arg.map { |v| puppet_to_gem_version(v) }
when String
puppet_to_gem_version(arg)
else
# Gem::Requirement, do nothing
arg
end
end
module Librarian
class Manifest
class Version
def initialize(*args)
args = initialize_normalize_args(args)
versions = Librarian::Puppet::VersionMapper.new.puppet_to_gem_versions(args)
self.backing = Gem::Version.new(*versions)
end

# convert Puppet '1.x' versions to gem supported versions '~>1.0'
# http://docs.puppetlabs.com/puppet/2.7/reference/modules_publishing.html
def puppet_to_gem_version(version)
matched = /(.*)\.x/.match(version)
matched.nil? ? version : "~>#{matched[1]}.0"
def to_puppet_version
Librarian::Puppet::VersionMapper.new.gem_to_puppet_version(backing)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/librarian/puppet/source/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def versions
end

def dependencies(version)
data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
data = api_call("api/v1/releases.json?module=#{name}&version=#{version.to_puppet_version}")
data[name].first['dependencies']
end

Expand Down Expand Up @@ -223,7 +223,7 @@ def install!(manifest)
manifest.source == self or raise ArgumentError

name = manifest.name
version = manifest.version
version = manifest.version.to_puppet_version
install_path = install_path(name)
repo = repo(name)

Expand Down
42 changes: 42 additions & 0 deletions lib/librarian/puppet/version_mapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Librarian
module Puppet
class VersionMapper
def puppet_to_gem_versions(args)
args.map do |arg|
case arg
when Array
arg.map { |v| puppet_to_gem_version(v) }
when String
puppet_to_gem_version(arg)
else
# Gem::Requirement, do nothing
arg
end
end
end

def puppet_to_gem_version(version)
puppet_semver_to_gem_version(puppet_rc_to_gem_version(version))
end

# convert Puppet '1.x' versions to gem supported versions '~>1.0'
# http://docs.puppetlabs.com/puppet/2.7/reference/modules_publishing.html
def puppet_semver_to_gem_version(version)
matched = /(.*)\.x/.match(version)
matched.nil? ? version : "~>#{matched[1]}.0"
end

# convert Puppet '1.0-rc1' style versions to gem supported versions '1.0.rc1'
def puppet_rc_to_gem_version(version)
#raise version if version == '0.5.0-rc1'
matched = /(.*)-([A-Za-z]*[0-9]*)$/.match(version)
matched.nil? ? version : "#{matched[1]}.#{matched[2]}"
end

def gem_to_puppet_version(version)
matched = /(.*).(rc[0-9]*)$/.match(version.to_s)
matched.nil? ? version.to_s : "#{matched[1]}-#{matched[2]}"
end
end
end
end

0 comments on commit 996eb9a

Please sign in to comment.