class Licensed::Sources::Gradle
Constants
- DEFAULT_CONFIGURATIONS
- GRADLE_LICENSES_CSV_NAME
- GRADLE_LICENSES_PATH
Public Instance Methods
Source
# File lib/licensed/sources/gradle.rb, line 42 def enabled? !executable.to_s.empty? && File.exist?(config.pwd.join("build.gradle")) end
Source
# File lib/licensed/sources/gradle.rb, line 46 def enumerate_dependencies JSON.parse(gradle_runner.run("printDependencies")).map do |package| name = "#{package['group']}:#{package['name']}" Dependency.new( name: name, version: package["version"], path: config.pwd, url: package_url(name: name, version: package["version"]), metadata: { "type" => Gradle.type, } ) end end
Private Instance Methods
Source
# File lib/licensed/sources/gradle.rb, line 79 def configurations @configurations ||= begin if configurations = config.dig("gradle", "configurations") Array(configurations) else DEFAULT_CONFIGURATIONS end end end
Returns the configurations to include in license generation. Defaults to [“runtime”, “runtimeClasspath”]
Source
# File lib/licensed/sources/gradle.rb, line 98 def csv_key(name:, version:) "#{name}-#{version}" end
Returns a key to uniquely identify a name and version in the obtained CSV content
Source
# File lib/licensed/sources/gradle.rb, line 63 def executable return @executable if defined?(@executable) @executable = begin return gradlew if File.executable?(gradlew) "gradle" if Licensed::Shell.tool_available?("gradle") end end
Source
# File lib/licensed/sources/gradle.rb, line 73 def gradle_runner @gradle_runner ||= Runner.new(configurations, executable) end
Source
# File lib/licensed/sources/gradle.rb, line 90 def gradlew @gradlew ||= begin gradlew = config.dig("gradle", "gradlew") config.root.join(gradlew || "gradlew").to_s end end
Returns the path to the Gradle
wrapper.
Source
# File lib/licensed/sources/gradle.rb, line 110 def load_csv begin # create the CSV file including dependency license urls using the gradle plugin gradle_licenses_dir = File.join(config.root, GRADLE_LICENSES_PATH) gradle_runner.run("generateLicenseReport") # parse the CSV report for dependency license urls CSV.foreach(File.join(gradle_licenses_dir, GRADLE_LICENSES_CSV_NAME), headers: true).each_with_object({}) do |row, hsh| name, _, version = row["artifact"].rpartition(":") key = csv_key(name: name, version: version) hsh[key] = row["moduleLicenseUrl"] end ensure FileUtils.rm_rf(gradle_licenses_dir) end end
Source
# File lib/licensed/sources/gradle.rb, line 102 def package_url(name:, version:) # load and memoize the license report CSV @urls ||= load_csv # uniquely identify a name and version in the obtained CSV content @urls["#{name}-#{version}"] end
Source
# File lib/licensed/sources/gradle.rb, line 128 def url_for(dependency) @csv[csv_key(name: dependency.name, version: dependency.version)] end
Returns the cached url for the given dependency