Sha256: 818f939d16785b62e4629be29cdbfe19a8337a09ef0f95f5f02de677ae1c3a7e

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

require 'xmlsimple'
require_relative 'gradle_dependency_finder'

module LicenseFinder
  class Gradle < PackageManager
    def initialize(options={})
      super
      @command = options[:gradle_command] || 'gradle --console plain'
      @include_groups = options[:gradle_include_groups]
    end

    def current_packages
      command = "#{@command} downloadLicenses"
      output, success = Dir.chdir(project_path) { capture(command) }
      raise "Command '#{command}' failed to execute: #{output}" unless success

      dependencies = GradleDependencyFinder.new(project_path).dependencies
      packages = dependencies.flat_map do |xml_file|
        options = {'GroupTags' => {'dependencies' => 'dependency'}}
        contents = XmlSimple.xml_in(xml_file, options).fetch('dependency', [])
        contents.map do |dep|
          GradlePackage.new(dep, logger: logger, include_groups: @include_groups)
        end
      end

      packages.uniq
    end

    def self.package_management_command
      "gradle"
    end

    private

    def package_path
      project_path.join('build.gradle')
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
license_finder-2.1.2 lib/license_finder/package_managers/gradle.rb
license_finder-2.1.1 lib/license_finder/package_managers/gradle.rb
license_finder-2.1.0 lib/license_finder/package_managers/gradle.rb
license_finder-2.1.0.rc9 lib/license_finder/package_managers/gradle.rb
license_finder-2.1.0.rc8 lib/license_finder/package_managers/gradle.rb
license_finder-2.1.0.rc7 lib/license_finder/package_managers/gradle.rb