Skip to content

Commit

Permalink
Issue #108 Don't fail on malformed Modulefile from a git dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Sanchez committed Feb 12, 2014
1 parent 22b380d commit fbaed56
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 0.9.14

* Issue #108 Don't fail on malformed Modulefile from a git dependency

### 0.9.13

* Issue #176 Upgrade to librarian 0.1.2
Expand Down
7 changes: 7 additions & 0 deletions lib/librarian/puppet/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,11 @@ def to_s
end
end

class Logger
def warn(string = nil, &block)
return unless ui

ui.warn(string || yield)
end
end
end
21 changes: 12 additions & 9 deletions lib/librarian/puppet/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ def fetch_dependencies(name, version, extra)
dependencies = Set.new

if modulefile?
metadata = ::Puppet::ModuleTool::Metadata.new

::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)

metadata.dependencies.each do |dependency|
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
Expand All @@ -110,11 +106,18 @@ def forge_source
# Naming this method 'version' causes an exception to be raised.
def module_version
return '0.0.1' unless modulefile?
evaluate_modulefile(modulefile).version
end

metadata = ::Puppet::ModuleTool::Metadata.new
::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)

metadata.version
def evaluate_modulefile(modulefile)
metadata = ::Puppet::ModuleTool::Metadata.new
begin
::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
rescue ArgumentError, SyntaxError => error
warn { "Unable to parse #{modulefile}, ignoring: #{error}" }
metadata.version = '0.0.1'
end
metadata
end

def modulefile
Expand Down
3 changes: 3 additions & 0 deletions lib/librarian/puppet/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def debug(*args, &block)
def info(*args, &block)
environment.logger.info(*args, &block)
end
def warn(*args, &block)
environment.logger.warn(*args, &block)
end

# workaround Issue #173 FileUtils.cp_r will fail if there is a symlink that points to a missing file
# or when the symlink is copied before the target file when preserve is true
Expand Down

0 comments on commit fbaed56

Please sign in to comment.