Class: LicenseFinder::Spm

Inherits:
PackageManager show all
Defined in:
lib/license_finder/package_managers/spm.rb

Defined Under Namespace

Classes: SpmError

Instance Method Summary collapse

Methods inherited from PackageManager

#active?, #command_exists?, #current_packages_with_relations, #detected_package_path, id, #initialize, #installed?, #prepare, #project_root?, takes_priority_over

Constructor Details

This class inherits a constructor from LicenseFinder::PackageManager

Instance Method Details

#current_packagesObject



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
# File 'lib/license_finder/package_managers/spm.rb', line 9

def current_packages
  unless File.exist?(workspace_state_path)
    raise SpmError, 'No checked-out SPM packages found.
      Please install your dependencies first.'
  end

  workspace_state = JSON.parse(IO.read(workspace_state_path))
  workspace_state['object']['dependencies'].map do |dependency|
    package_ref = dependency['packageRef']
    checkout_state = dependency['state']['checkoutState']

    subpath = dependency['subpath']
    package_name = package_ref['name']
    package_version = checkout_state['version'] || checkout_state['revision']
    homepage = package_ref['path']

    SpmPackage.new(
      package_name,
      package_version,
      license_text(subpath),
      logger: logger,
      install_path: project_checkout(subpath),
      homepage: homepage
    )
  end
end

#package_management_commandObject



36
37
38
# File 'lib/license_finder/package_managers/spm.rb', line 36

def package_management_command
  LicenseFinder::Platform.darwin? ? 'xcodebuild' : 'swift'
end

#possible_package_pathsObject



44
45
46
# File 'lib/license_finder/package_managers/spm.rb', line 44

def possible_package_paths
  [workspace_state_path]
end

#prepare_commandObject



40
41
42
# File 'lib/license_finder/package_managers/spm.rb', line 40

def prepare_command
  LicenseFinder::Platform.darwin? ? 'xcodebuild -resolvePackageDependencies' : 'swift package resolve'
end