class Licensed::Sources::Gradle::Runner
The Gradle::Runner
class is a wrapper which provides an interface to run gradle commands with the init script initialized
Public Class Methods
Source
# File lib/licensed/sources/gradle.rb, line 135 def initialize(configurations, executable) @executable = executable @init_script = create_init_script(configurations) end
Public Instance Methods
Source
# File lib/licensed/sources/gradle.rb, line 140 def run(command) args = [command] # The configuration cache is an incubating feature that can be activated manually. # The gradle plugin for licenses does not support it so we prevent it to run for gradle version supporting it. args << "--no-configuration-cache" if gradle_version >= Gem::Version.new("6.6") Licensed::Shell.execute(@executable, "-q", "--init-script", @init_script.path, *args) end
Private Instance Methods
Source
# File lib/licensed/sources/gradle.rb, line 150 def create_init_script(configurations) # we need to create extensions in the event that the user hasn't configured custom configurations # to avoid hitting errors where core Gradle configurations are set with canBeResolved=false configuration_map = configurations.map { |c| [c, "licensed#{c}"] }.to_h configuration_dsl = configuration_map.map { |orig, custom| "#{custom}.extendsFrom(#{orig})" } f = Tempfile.new(["init", ".gradle"]) f.write( <<~EOF import com.github.jk1.license.render.CsvReportRenderer import com.github.jk1.license.filter.LicenseBundleNormalizer final configs = #{configuration_map.values.inspect} initscript { repositories { maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "com.github.jk1:gradle-license-report:#{gradle_version >= Gem::Version.new("7.0") ? "2.0" : "1.17"}" } } allprojects { configurations { #{configuration_dsl.join("\n") } } apply plugin: com.github.jk1.license.LicenseReportPlugin licenseReport { outputDir = "$rootDir/#{GRADLE_LICENSES_PATH}" configurations = configs renderers = [new CsvReportRenderer()] filters = [new LicenseBundleNormalizer()] } task printDependencies { doLast { def dependencies = [] configs.each { configurations[it].resolvedConfiguration.resolvedArtifacts.each { artifact -> def id = artifact.moduleVersion.id dependencies << "{ \\"group\\": \\"${id.group}\\", \\"name\\": \\"${id.name}\\", \\"version\\": \\"${id.version}\\" }" } } println "[${dependencies.join(", ")}]" } } } EOF ) f.close f end
Source
# File lib/licensed/sources/gradle.rb, line 207 def gradle_version @gradle_version ||= begin version = Licensed::Shell.execute(@executable, "--version").scan(/Gradle [\d+]\.[\d+]/).last.split(" ").last Gem::Version.new(version) end end
Returns the version of gradle used during execution