Class: Librarian::Puppet::Source::Git

Inherits:
Source::Git show all
Includes:
Local, Util
Defined in:
lib/librarian/puppet/source/git.rb

Instance Method Summary collapse

Methods included from Util

#cp_r, #debug, #info

Methods included from Local

#install!

Methods inherited from Source::Git

#hash

Instance Method Details

#cache!Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/librarian/puppet/source/git.rb', line 28

def cache!
  return vendor_checkout! if vendor_cached?

  if environment.local?
    raise Error, "Could not find a local copy of #{uri} at #{sha}."
  end

  super

  cache_in_vendor(repository.path) if environment.vendor?
end

#cache_in_vendor(tmp_path) ⇒ Object



59
60
61
62
63
# File 'lib/librarian/puppet/source/git.rb', line 59

def cache_in_vendor(tmp_path)
  Dir.chdir(tmp_path.to_s) do
    %x{git archive #{sha} | gzip > #{vendor_tgz}}
  end
end

#fetch_dependencies(name, version, extra) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/librarian/puppet/source/git.rb', line 71

def fetch_dependencies(name, version, extra)
  dependencies = Set.new

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

    ::Puppet::ModuleTool::ModulefileReader.evaluate(, 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)
    end
  end

  if specfile?
    spec = environment.dsl(Pathname(specfile))
    dependencies.merge spec.dependencies
  end

  dependencies
end

#fetch_version(name, extra) ⇒ Object



65
66
67
68
69
# File 'lib/librarian/puppet/source/git.rb', line 65

def fetch_version(name, extra)
  cache!
  found_path = found_path(name)
  module_version
end

#forge_sourceObject



95
96
97
# File 'lib/librarian/puppet/source/git.rb', line 95

def forge_source
  Forge.from_lock_options(environment, :remote=>"http://forge.puppetlabs.com")
end

#vendor_cached?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/librarian/puppet/source/git.rb', line 44

def vendor_cached?
  vendor_tgz.exist?
end

#vendor_checkout!Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/librarian/puppet/source/git.rb', line 48

def vendor_checkout!
  repository.path.rmtree if repository.path.exist?
  repository.path.mkpath

  Dir.chdir(repository.path.to_s) do
    %x{tar xzf #{vendor_tgz}}
  end

  repository_cached!
end

#vendor_tgzObject



40
41
42
# File 'lib/librarian/puppet/source/git.rb', line 40

def vendor_tgz
  environment.vendor_source + "#{sha}.tar.gz"
end