Module: Librarian::Puppet::Source::Local

Includes:
Util
Included in:
Git, Path
Defined in:
lib/librarian/puppet/source/local.rb

Instance Method Summary collapse

Methods included from Util

#clean_uri, #cp_r, #debug, #info, #module_name, #normalize_name, #rsync?, #warn

Instance Method Details

#fetch_dependencies(name, version, extra) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/librarian/puppet/source/local.rb', line 110

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

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

  ['dependencies'].each do |d|
    if environment.use_forge
      gem_requirement = Librarian::Dependency::Requirement.new(d['version_requirement']).to_gem_requirement
      new_dependency = Dependency.new(d['name'], gem_requirement, forge_source)
      dependencies << new_dependency
    end

    dependencies
  end

  dependencies
end

#fetch_version(name, extra) ⇒ Object



104
105
106
107
108
# File 'lib/librarian/puppet/source/local.rb', line 104

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

#forge_sourceObject



131
132
133
# File 'lib/librarian/puppet/source/local.rb', line 131

def forge_source
  Forge.default
end

#install!(manifest) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/librarian/puppet/source/local.rb', line 9

def install!(manifest)
  manifest.source == self or raise ArgumentError

  if environment.verbose?
    info { "Processing #{manifest.name}" }
  end

  debug { "Installing #{manifest}" }

  name, version = manifest.name, manifest.version
  found_path = found_path(name)

  # We only care about this if we're fetching from a Forge
  if found_path || self.is_a?(Librarian::Puppet::Source::Forge)
    raise Error, "Path for #{name} doesn't contain a puppet module" if found_path.nil?

    unless name.include? '/' or name.include? '-'
      warn { "Invalid module name '#{name}', you should qualify it with 'ORGANIZATION-#{name}' for resolution to work correctly" }
    end

    install_path = environment.install_path.join(module_name(name))
  elsif !repository_cached
    raise Error, "Could not find cached version of #{name} for installation"
  else
    found_path = repository_cache_path
    install_path = environment.project_path + path.to_s
  end

  install_repo = Git::Repository.new(environment,install_path)

  if install_repo.git?
    _install_path = relative_path_to(install_path)

    if environment.git_destructive
      debug { "Performing git hard reset of '#{_install_path}'" }

      install_repo.reset_hard!
      install_repo.clean!
    end

    if install_repo.dirty?
        warn { "#{install_repo.dirty?}, skipping..." }
    else
      # Try to do nicer git operations when possible
      _remote_repo = 'librarian_origin'

      begin
        Librarian::Posix.run!(%W{git remote add #{_remote_repo} #{repository_cache_path}}, :chdir => _install_path)
      rescue Librarian::Posix::CommandFailure => e
        unless e.to_s =~ /already exists/
          raise Error, "Could not update git repository at #{_install_path}"
        end
      end

      install_repo.fetch!(_remote_repo)

      if environment.verbose?
        warn "Checking out #{ref} in #{_install_path}"
      end
      install_repo.checkout!(ref)

      begin
        _target_ref = ref

        # Handle branches vs absolute refs
        if repository.remote_branch_names[repository.default_remote].include?(_target_ref)
          _target_ref = "#{repository.default_remote}/#{_target_ref}"
        end

        ff_output = Librarian::Posix.run!(%W{git pull --ff-only #{_remote_repo} #{_target_ref}}, :chdir => _install_path)

        if ff_output =~ /Updating\s+.*\.\.(.*)\s*$/
          warn { "Updated '#{_install_path}' to #{$1}" }
        end
      rescue Librarian::Posix::CommandFailure => e
        warn { "Fast forward of git repo at '#{_install_path}' failed...skipping" }
      end

      begin
        Librarian::Posix.run!(%W{git remote rm #{_remote_repo}}, :chdir => _install_path)
      rescue Librarian::Posix::CommandFailure => e
        # We don't really care if this fails.
        debug { "Removal of the '#{_remote_repo}' git remote failed" }
      end
    end
  else
    if install_path.exist? && rsync? != true
      debug { "Deleting #{relative_path_to(install_path)}" }
      install_path.rmtree
    end

    install_perform_step_copy!(found_path, install_path)
  end
end