lib/rake_dependencies/tasks/extract.rb in rake_dependencies-3.6.0.pre.4 vs lib/rake_dependencies/tasks/extract.rb in rake_dependencies-3.6.0.pre.8
- old
+ new
@@ -4,13 +4,15 @@
require 'zip'
require 'rubygems'
require_relative '../template'
require_relative '../extractors'
+require_relative '../null_logger'
module RakeDependencies
module Tasks
+ # rubocop:disable Metrics/ClassLength
class Extract < RakeFactory::Task
default_name :extract
default_description(RakeFactory::DynamicValue.new do |t|
"Extract #{t.dependency} archive"
end)
@@ -36,19 +38,32 @@
parameter :file_name_template, required: true
parameter :source_binary_name_template
parameter :target_binary_name_template
parameter :strip_path_template
+ parameter :logger, default: NullLogger.new
+
+ # rubocop:disable Metrics/BlockLength
action do
+ logger.info("Extracting '#{dependency}'...")
+
+ logger.debug(
+ "Using parameters: #{parameters.merge(platform: platform.to_s)}."
+ )
+
distribution_file_name = interpolate_file_name_template(parameters)
distribution_file_directory = relative_to_path(distribution_directory)
distribution_file_path = File.join(
distribution_file_directory, distribution_file_name
)
+ logger.debug("Using distribution file path: #{distribution_file_path}.")
+
extraction_path = relative_to_path(binary_directory)
+ logger.debug("Using extraction path: #{extraction_path}.")
+
options = {}
if strip_path_template
options[:strip_path] = interpolate_strip_path_template(parameters)
end
@@ -57,25 +72,30 @@
interpolate_source_binary_name_template(parameters)
options[:rename_to] =
interpolate_target_binary_name_template(parameters)
end
+ logger.debug("Using extraction options: #{options}.")
+
extractor = extractor_for_extension.new(
distribution_file_path,
extraction_path,
options
)
extractor.extract
+
+ logger.info('Extracted.')
end
+ # rubocop:enable Metrics/BlockLength
def parameters
{
- version: version,
- platform: platform,
- platform_cpu_name: platform_cpu_name,
- platform_os_name: platform_os_name,
- ext: ext
+ version:,
+ platform:,
+ platform_cpu_name:,
+ platform_os_name:,
+ ext:
}
end
def interpolate_template(template, parameters)
Template.new(template)
@@ -132,7 +152,8 @@
else
raise "Unknown type: #{type}"
end
end
end
+ # rubocop:enable Metrics/ClassLength
end
end