[DRE-commits] [librarian-puppet] 43/153: Version in dependencies with `metadata.json` is ignored

Stig Sandbeck Mathisen ssm at debian.org
Wed Jun 1 20:30:39 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 2f0423e883b374ff805500acf1ab9986f2690e1d
Author: Carlos Sanchez <csanchez at maestrodev.com>
Date:   Mon Aug 4 14:00:25 2014 +0200

    Version in dependencies with `metadata.json` is ignored
    
    Fix test, apt tag 1.5.0 had the wrong version in metadata.json
---
 Changelog.md                         |  9 +++++++
 features/package.feature             |  4 ++--
 lib/librarian/puppet/source/local.rb | 46 +++++++++++++++++++++++-------------
 3 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 1852786..6350654 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -2,6 +2,10 @@
 
 ## From 1.1.x Librarian-Puppet requires Ruby >= 1.9, uses Puppet Forge API v3. For Ruby 1.8 use 1.0.x
 
+### 1.3.1
+
+ * Version in dependencies with `metadata.json` is ignored
+
 ### 1.3.0
 
  * If no Puppetfile is present default to use the `metadata.json` or `Modulefile`
@@ -38,6 +42,11 @@
 
 ## 1.0.x: Works on Ruby 1.8, using Puppet Forge API v1
 
+
+### 1.0.8
+
+ * Version in dependencies with `metadata.json` is ignored
+
 ### 1.0.7
 
  * If no Puppetfile is present default to use the `metadata.json` or `Modulefile`
diff --git a/features/package.feature b/features/package.feature
index 9f2eb08..43699fc 100644
--- a/features/package.feature
+++ b/features/package.feature
@@ -22,7 +22,7 @@ Feature: cli/package
     """
     forge "http://forge.puppetlabs.com"
 
-    mod 'puppetlabs/apt', '1.4.0', :git => 'https://github.com/puppetlabs/puppetlabs-apt.git', :ref => '1.4.0'
+    mod 'puppetlabs/apt', '1.5.0', :git => 'https://github.com/puppetlabs/puppetlabs-apt.git', :ref => '1.5.0'
     mod 'puppetlabs/stdlib', '4.1.0'
     """
     When I run `librarian-puppet package --verbose`
@@ -30,7 +30,7 @@ Feature: cli/package
     And the file "modules/apt/Modulefile" should match /name *'puppetlabs-apt'/
     And the file "modules/stdlib/metadata.json" should match /"name": "puppetlabs-stdlib"/
     And the following files should exist:
-      | vendor/puppet/source/924e89289b93db60ef0f16a4e71579fa88e037a6.tar.gz |
+      | vendor/puppet/source/e5657a61b9ac0dd3c00002c777b0d3c615bb98a5.tar.gz |
       | vendor/puppet/cache/puppetlabs-stdlib-4.1.0.tar.gz                   |
 
   @github
diff --git a/lib/librarian/puppet/source/local.rb b/lib/librarian/puppet/source/local.rb
index 9d3bbce..34f9c92 100644
--- a/lib/librarian/puppet/source/local.rb
+++ b/lib/librarian/puppet/source/local.rb
@@ -37,19 +37,7 @@ module Librarian
         def fetch_dependencies(name, version, extra)
           dependencies = Set.new
 
-          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|
+          parsed_metadata['dependencies'].each do |d|
             gem_requirement = Requirement.new(d['version_requirement']).gem_requirement
             dependencies << Dependency.new(d['name'], gem_requirement, forge_source)
           end
@@ -63,15 +51,19 @@ module Librarian
         end
 
         def forge_source
-          Forge.from_lock_options(environment, :remote=>"http://forge.puppetlabs.com")
+          Forge.from_lock_options(environment, :remote => "https://forgeapi.puppetlabs.com")
         end
 
         private
 
         # Naming this method 'version' causes an exception to be raised.
         def module_version
-          return '0.0.1' unless modulefile?
-          evaluate_modulefile(modulefile).version
+          if parsed_metadata['version']
+            parsed_metadata['version']
+          else
+            warn { "Module #{to_s} does not have version, defaulting to 0.0.1" }
+            '0.0.1'
+          end
         end
 
         def require_puppet
@@ -106,6 +98,28 @@ module Librarian
           metadata
         end
 
+        def parsed_metadata
+          @metadata ||= if metadata?
+            JSON.parse(File.read(metadata))
+          elsif modulefile?
+            # translate Modulefile to metadata.json
+            evaluated = evaluate_modulefile(modulefile)
+            {
+              'version' => evaluated.version,
+              'dependencies' => evaluated.dependencies.map do |dependency|
+                {
+                  'name' => dependency.instance_variable_get(:@full_module_name),
+                  'version_requirement' => dependency.instance_variable_get(:@version_requirement)
+                }
+              end
+            }
+          else
+            warn { "Could not find metadata.json nor Modulefile at #{filesystem_path}" }
+            {}
+          end
+          @metadata
+        end
+
         def modulefile
           File.join(filesystem_path, 'Modulefile')
         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