Skip to content

Commit

Permalink
Use gradle CLI to format command
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisBoudreau committed Jan 3, 2023
1 parent 4f3ba1d commit f71db05
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/licensed/sources/gradle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def enabled?
end

def enumerate_dependencies
JSON.parse(gradle_runner.run(format_command("printDependencies"))).map do |package|
JSON.parse(gradle_runner.run("printDependencies")).map do |package|
name = "#{package['group']}:#{package['name']}"
Dependency.new(
name: name,
Expand All @@ -63,7 +63,7 @@ def enumerate_dependencies
private

def gradle_runner
@gradle_runner ||= Runner.new(config.root, configurations)
@gradle_runner ||= Runner.new(config.pwd, configurations)
end

# Returns the configurations to include in license generation.
Expand All @@ -78,14 +78,6 @@ def configurations
end
end

# Prefixes the gradle command with the project name for multi-build projects.
def format_command(command)
if config.source_path != config.root
project = File.basename(config.source_path)
end
project.nil? ? command : "#{project}:#{command}"
end

# Returns a key to uniquely identify a name and version in the obtained CSV content
def csv_key(name:, version:)
"#{name}-#{version}"
Expand Down Expand Up @@ -129,11 +121,12 @@ def initialize(root_path, configurations)
@configurations = configurations
end

def run(*args)
def run(command)
Dir.chdir(@root_path) do
Tempfile.create(["init", ".gradle"], @root_path) do |f|
f.write(init_script(@configurations))
f.close
args = [format_command(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 >= "6.6"
Expand Down Expand Up @@ -204,6 +197,12 @@ def id = artifact.moduleVersion.id
}
EOF
end

# Prefixes the gradle command with the project name for multi-build projects.
def format_command(command)
path = Licensed::Shell.execute(executable, "properties", "--property", "path", "-Dorg.gradle.logging.level=quiet")&.split(" ").last
path == ":" ? command : "#{path}:#{command}"
end
end
end
end
Expand Down

0 comments on commit f71db05

Please sign in to comment.