diff options
Diffstat (limited to 'lib/license/finder/ext/go_modules.rb')
| -rw-r--r-- | lib/license/finder/ext/go_modules.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/license/finder/ext/go_modules.rb b/lib/license/finder/ext/go_modules.rb new file mode 100644 index 0000000..2ef3aa2 --- /dev/null +++ b/lib/license/finder/ext/go_modules.rb @@ -0,0 +1,36 @@ +module LicenseFinder + class GoModules + def prepare + shell.execute([:go, :mod, :tidy, '-v', '&&', :go, :mod, :vendor, '-v']) + end + + def active? + Dir[project_path.join('go.sum')].any? + end + + def current_packages + stdout, _stderr, status = shell.execute([ + :go, :list, '-m', '-mod=vendor', + '-f', "'{{.Path}},{{.Version}},{{.Dir}}'", :all + ]) + return [] unless status.success? + + stdout.lines.map do |line| + name, version, dir = line.chomp.split(',') + next if Pathname(dir).cleanpath == absolute_project_path + + Package.new(name, version, install_path: dir) + end.compact + end + + private + + def shell + @shell ||= ::License::Management::Shell.new + end + + def absolute_project_path + @absolute_project_path ||= Pathname(project_path).cleanpath + end + end +end |
