lib/cc/cli/config_generator.rb in codeclimate-0.18.3 vs lib/cc/cli/config_generator.rb in codeclimate-0.18.4
- old
+ new
@@ -1,13 +1,16 @@
+require "posix/spawn"
require "shellwords"
module CC
module CLI
class ConfigGenerator
CODECLIMATE_YAML = Command::CODECLIMATE_YAML
AUTO_EXCLUDE_PATHS = %w(config/ db/ dist/ features/ node_modules/ script/ spec/ test/ tests/ vendor/).freeze
+ ConfigGeneratorError = Class.new(StandardError)
+
def self.for(filesystem, engine_registry, upgrade_requested)
if upgrade_requested && upgrade_needed?(filesystem)
UpgradeConfigGenerator.new(filesystem, engine_registry)
else
ConfigGenerator.new(filesystem, engine_registry)
@@ -78,14 +81,24 @@
def workspace_files
@workspace_files ||= Dir.chdir(filesystem.root) do
if non_excluded_paths.empty?
[]
else
- find_cmd = "find #{non_excluded_paths.map(&:shellescape).join(' ')} -type f -print0"
- `#{find_cmd}`.strip.split("\0").map do |path|
- path.sub(%r{^\.\/}, "")
- end
+ find_workspace_files
end
+ end
+ end
+
+ def find_workspace_files
+ find_cmd = %w[find] + non_excluded_paths + %w[-type f -print0]
+ child = POSIX::Spawn::Child.new(*find_cmd)
+
+ if child.status.success?
+ child.out.strip.split("\0").map do |path|
+ path.sub(%r{^\.\/}, "")
+ end
+ else
+ raise ConfigGeneratorError, "Failed to find analyzable files.\nRan '#{find_cmd.shelljoin}', exited with code #{child.status.to_i} and stderr:\n'#{child.err}'"
end
end
end
end
end