summaryrefslogtreecommitdiff
path: root/lib/license/finder/ext/package_manager.rb
blob: f90a8eb4b5d95fb18b637c85e4247d7efc5feaaa (plain)
1
2
3
4
5
6
7
8
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
# frozen_string_literal: true

module LicenseFinder
  class PackageManager
    def shell
      ::License::Management.shell
    end

    def log
      ::License::Management.logger
    end

    def tool_box
      @tool_box ||= ::License::Management::ToolBox.new(shell, project_path)
    end

    def prepare
      create_vendor_path
      return unless prepare_command

      within_project_path do
        shell.execute(prepare_command)
      end
    end

    def current_packages_with_relations
      current_packages
    rescue StandardError => e
      log.error(e)
      raise e unless @prepare_no_fail

      []
    end

    protected

    def vendor_path
      @vendor_path ||= Pathname.pwd.join('.gitlab', 'cache', 'vendor')
    end

    def create_vendor_path
      shell.execute([:mkdir, '-p', vendor_path]) unless vendor_path.exist?
    end

    def within_project_path
      Dir.chdir(project_path) { yield }
    end
  end
end