[DRE-commits] [librarian-puppet] 33/153: Issue #220 Add support for metadata.json

Stig Sandbeck Mathisen ssm at debian.org
Wed Jun 1 20:30:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository librarian-puppet.

commit e0ebe202a8b7ec5e96e29e40057ad7b394a42613
Author: Carlos Sanchez <csanchez at maestrodev.com>
Date:   Mon Jul 28 19:22:44 2014 +0200

    Issue #220 Add support for metadata.json
---
 Changelog.md                         |  6 ++--
 features/install/git.feature         | 12 +++++++-
 lib/librarian/puppet/source/local.rb | 55 +++++++++++++++++++++++++-----------
 lib/librarian/puppet/version.rb      |  2 +-
 4 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 690cd9f..753cb77 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,9 +1,10 @@
 # Changelog
 
-## 1.1.x: Requires Ruby >= 1.9, uses Puppet Forge API v3
+## From 1.1.x Librarian-Puppet requires Ruby >= 1.9, uses Puppet Forge API v3. For Ruby 1.8 use 1.0.x
 
-### 1.1.4
+### 1.2.0
 
+ * [Issue #220](https://github.com/rodjek/librarian-puppet/issues/220) Add support for metadata.json
  * [Issue #242](https://github.com/rodjek/librarian-puppet/issues/242) Get organization from name correctly if name has multiple dashes
 
 ### 1.1.3
@@ -32,6 +33,7 @@
 
 ### 1.0.6
 
+ * [Issue #220](https://github.com/rodjek/librarian-puppet/issues/220) Add support for metadata.json
  * [Issue #242](https://github.com/rodjek/librarian-puppet/issues/242) Get organization from name correctly if name has multiple dashes
 
 ### 1.0.5
diff --git a/features/install/git.feature b/features/install/git.feature
index 8ae9a59..7696336 100644
--- a/features/install/git.feature
+++ b/features/install/git.feature
@@ -70,6 +70,16 @@ Feature: cli/install/git
     And the file "modules/postgresql/.git/HEAD" should match /183d401a3ffeb2e83372dfcc05f5b6bab25034b1/
     And the file "modules/stdlib/metadata.json" should match /"name": "puppetlabs-stdlib"/
 
+  Scenario: Install a module with dependencies specified in metadata.json
+    Given a file named "Puppetfile" with:
+    """
+    mod 'puppetlabs-apt', :git => 'https://github.com/puppetlabs/puppetlabs-apt.git', :ref => '1.5.2'
+    """
+    When I run `librarian-puppet install`
+    Then the exit status should be 0
+    And the file "modules/stdlib/metadata.json" should match /"name": "puppetlabs-stdlib"/
+    And the file "modules/apt/metadata.json" should match /"name": "puppetlabs-apt"/
+
   Scenario: Install a module with dependencies specified in a Puppetfile
     Given a file named "Puppetfile" with:
     """
@@ -105,7 +115,7 @@ Feature: cli/install/git
     """
     forge "http://forge.puppetlabs.com"
 
-    mod 'test', :git => 'https://github.com/rodjek/librarian-puppet.git', :path => 'features/examples/test'
+    mod 'librarian-test', :git => 'https://github.com/rodjek/librarian-puppet.git', :path => 'features/examples/test'
     """
     When I run `librarian-puppet install`
     Then the exit status should be 0
diff --git a/lib/librarian/puppet/source/local.rb b/lib/librarian/puppet/source/local.rb
index 3848d38..a295492 100644
--- a/lib/librarian/puppet/source/local.rb
+++ b/lib/librarian/puppet/source/local.rb
@@ -1,16 +1,5 @@
 require 'librarian/puppet/util'
 
-begin
-  require 'puppet'
-  require 'puppet/module_tool'
-rescue LoadError
-  $stderr.puts <<-EOF
-Unable to load puppet, the puppet gem is required for :git and :path source.
-Install it with: gem install puppet
-  EOF
-  exit 1
-end
-
 module Librarian
   module Puppet
     module Source
@@ -48,13 +37,21 @@ module Librarian
         def fetch_dependencies(name, version, extra)
           dependencies = Set.new
 
-          if modulefile?
-            evaluate_modulefile(modulefile).dependencies.each do |dependency|
-              dependency_name = dependency.instance_variable_get(:@full_module_name)
-              version = dependency.instance_variable_get(:@version_requirement)
-              gem_requirement = Requirement.new(version).gem_requirement
-              dependencies << Dependency.new(dependency_name, gem_requirement, forge_source)
+          dependencyList = if metadata?
+            JSON.parse(File.read(metadata))['dependencies']
+          elsif modulefile?
+            evaluate_modulefile(modulefile).dependencies.map do |dependency|
+              {
+                'name' => dependency.instance_variable_get(:@full_module_name),
+                'version_requirement' => dependency.instance_variable_get(:@version_requirement)
+              }
             end
+          else []
+          end
+
+          dependencyList.each do |d|
+            gem_requirement = Requirement.new(d['version_requirement']).gem_requirement
+            dependencies << Dependency.new(d['name'], gem_requirement, forge_source)
           end
 
           if specfile?
@@ -77,7 +74,23 @@ module Librarian
           evaluate_modulefile(modulefile).version
         end
 
+        def require_puppet
+          begin
+            require 'puppet'
+            require 'puppet/module_tool'
+          rescue LoadError
+            $stderr.puts <<-EOF
+          Unable to load puppet, the puppet gem is required for :git and :path source.
+          Install it with: gem install puppet
+            EOF
+            exit 1
+          end
+          true
+        end
+
         def evaluate_modulefile(modulefile)
+          @@require_puppet ||= require_puppet
+
           metadata = ::Puppet::ModuleTool::Metadata.new
           begin
             ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
@@ -100,6 +113,14 @@ module Librarian
           File.exists?(modulefile)
         end
 
+        def metadata
+          File.join(filesystem_path, 'metadata.json')
+        end
+
+        def metadata?
+          File.exists?(metadata)
+        end
+
         def specfile
           File.join(filesystem_path, environment.specfile_name)
         end
diff --git a/lib/librarian/puppet/version.rb b/lib/librarian/puppet/version.rb
index 03c60b6..090f560 100644
--- a/lib/librarian/puppet/version.rb
+++ b/lib/librarian/puppet/version.rb
@@ -1,5 +1,5 @@
 module Librarian
   module Puppet
-    VERSION = "1.1.4"
+    VERSION = "1.2.0"
   end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/librarian-puppet.git



More information about the Pkg-ruby-extras-commits mailing list