diff --git a/Shantyfile b/Shantyfile index 55dbc68..4c4d49f 100644 --- a/Shantyfile +++ b/Shantyfile @@ -1,3 +1,4 @@ +# FIXME: This shouldn't need to be required, can be auto-discovered. require 'shanty/projects/ruby' require 'shanty/plugins/bundler' require 'shanty/plugins/rspec' diff --git a/lib/shanty.rb b/lib/shanty.rb index c1d9eaa..6f8deb6 100644 --- a/lib/shanty.rb +++ b/lib/shanty.rb @@ -12,14 +12,14 @@ module Shanty # Main shanty class class Shanty + # This is the root directory where the Shanty gem is located. Do not confuse this with the root of the repository + # in which Shanty is operating, which is available via the TaskEnv class. GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) def start! setup_i18n - task_env = TaskEnv.new - task_env.load! - Cli.new(task_env).run + Cli.new(TaskEnv.new).run end private diff --git a/lib/shanty/cli.rb b/lib/shanty/cli.rb index 31c1b9f..9c2a244 100644 --- a/lib/shanty/cli.rb +++ b/lib/shanty/cli.rb @@ -38,13 +38,9 @@ def setup_tasks def setup_task(name, task) command(name) do |c| c.description = I18n.t(task[:desc], default: task[:desc]) - + c.syntax = task[:syntax] add_options_to_command(task, c) - c.action do |args, options| - task = tasks[name] - options.default(Hash[defaults_for_options(task)]) - execute_task(name, task, args, options) - end + add_action_to_command(name, task, c) end end @@ -54,6 +50,14 @@ def add_options_to_command(task, command) end end + def add_action_to_command(name, task, command) + command.action do |args, options| + task = tasks[name] + options.default(Hash[defaults_for_options(task)]) + execute_task(name, task, args, options) + end + end + def execute_task(name, task, args, options) # We use allocate here beccause we do not want this to blow up because the class defines a constructor. # We cannot and do not support taskset classes needing constructors. @@ -77,7 +81,7 @@ def syntax_for_option(name, option) when :boolean "--#{name}" else - "--#{name} #{option[:type].upcase}" + "--#{name} #{(option[:type] || 'string').upcase}" end option[:required] ? "[#{syntax}]" : syntax diff --git a/lib/shanty/discoverers/gradle.rb b/lib/shanty/discoverers/gradle.rb deleted file mode 100644 index b042d99..0000000 --- a/lib/shanty/discoverers/gradle.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'shanty/discoverer' -require 'shanty/projects/static' - -module Shanty - # Gradle discoverer - class ShantyfileDiscoverer < Discoverer - def discover - Dir['**/build.gradle'].map do |path| - create_project( - File.dirname(path), - type: GradleProject, - options: { foo: 'bar' }, - plugins: [GradlePlugin], parents: [''] - ) - end - end - end -end diff --git a/lib/shanty/graph.rb b/lib/shanty/graph.rb index cc6f9f6..08721ba 100644 --- a/lib/shanty/graph.rb +++ b/lib/shanty/graph.rb @@ -15,7 +15,6 @@ class Graph # a graph structure of dependencies. def initialize(projects) @projects = sort_projects(link_projects(projects)) - @project_path_trie = Containers::Trie.new @projects.each do |project| diff --git a/lib/shanty/mutators/git.rb b/lib/shanty/mutators/git.rb index 5ab94f0..0a3d0de 100644 --- a/lib/shanty/mutators/git.rb +++ b/lib/shanty/mutators/git.rb @@ -10,7 +10,7 @@ def initialize def mutate(graph) git_root = `git rev-parse --show-toplevel`.strip - diff_files = `git diff --name-only #{@vcs_range.from_commit} #{@vcs_range.to_commit}`.split("\n") + diff_files = `git diff --name-only #{@vcs_range.from_commit} #{@vcs_range.to_commit} 2>/dev/null`.split("\n") diff_files.each do |path| next if path.nil? path = File.join(git_root, path) diff --git a/lib/shanty/project.rb b/lib/shanty/project.rb index 885bc2d..8f8cdb6 100644 --- a/lib/shanty/project.rb +++ b/lib/shanty/project.rb @@ -52,7 +52,7 @@ def artifact_path # # Returns a simple String representation of this instance. def to_s - "Name: #{name}" + "Name: #{name}, Type: #{self.class}" end # Public: Overriden String conversion method to return a more detailed @@ -67,5 +67,13 @@ def inspect options: options }.inspect end + + private + + def within_project_dir + Dir.chdir(path) do + yield + end + end end end diff --git a/lib/shanty/task_env.rb b/lib/shanty/task_env.rb index dba3af0..ab54b35 100644 --- a/lib/shanty/task_env.rb +++ b/lib/shanty/task_env.rb @@ -7,10 +7,12 @@ class TaskEnv CONFIG_FILE = '.shanty.yml' DEFAULT_CONFIG = {} - def load! - (config['require'] || {}).each do |requirement| - requirement = "#{requirement}/**/*.rb" unless requirement.include?('.rb') - Dir[requirement].each { |f| require f } + def initialize + Dir.chdir(root) do + (config['require'] || {}).each do |requirement| + requirement = "#{requirement}/**/*.rb" unless requirement.include?('.rb') + Dir[requirement].each { |f| require(File.join(root, f)) } + end end end @@ -18,8 +20,6 @@ def graph @graph ||= construct_project_graph end - private - def environment @environment = ENV['SHANTY_ENV'] || 'local' end @@ -28,6 +28,8 @@ def root @root ||= find_root end + private + def config return @config unless @config.nil? diff --git a/lib/shanty/task_set.rb b/lib/shanty/task_set.rb index b6490fb..234d93e 100644 --- a/lib/shanty/task_set.rb +++ b/lib/shanty/task_set.rb @@ -13,7 +13,8 @@ def self.inherited(task_set) @task_sets << task_set end - def self.desc(desc) + def self.desc(syntax, desc) + partial_task[:syntax] = syntax partial_task[:desc] = desc end diff --git a/lib/shanty/task_sets/basic.rb b/lib/shanty/task_sets/basic.rb index 65d1a23..179bbe0 100644 --- a/lib/shanty/task_sets/basic.rb +++ b/lib/shanty/task_sets/basic.rb @@ -5,13 +5,13 @@ module Shanty # Public: A set of basic tasks that can be applied to all projects and that # ship with the core of Shanty. - class BasicTasks < Shanty::TaskSet - desc 'tasks.init.desc' - def init + class BasicTasks < TaskSet + desc 'init', 'tasks.init.desc' + def init(_options, _task_env) # FIXME end - desc 'tasks.projects.desc' + desc 'projects [--changed] [--types TYPE,TYPE,...]', 'tasks.projects.desc' option :changed, type: :boolean, desc: 'tasks.common.options.changed' option :types, type: :array, desc: 'tasks.common.options.types' def projects(options, task_env) @@ -21,7 +21,7 @@ def projects(options, task_env) end end - desc 'tasks.build.desc' + desc 'build [--changed] [--watch] [--types TYPE,TYPE,...]', 'tasks.build.desc' option :changed, type: :boolean, desc: 'tasks.common.options.changed' option :watch, type: :boolean, desc: 'tasks.common.options.watch' option :types, type: :array, desc: 'tasks.common.options.types' @@ -32,7 +32,7 @@ def build(options, task_env) end end - desc 'tasks.test.desc' + desc 'test [--changed] [--watch] [--types TYPE,TYPE,...]', 'tasks.test.desc' option :changed, type: :boolean, desc: 'tasks.common.options.changed' option :watch, type: :boolean, desc: 'tasks.common.options.watch' option :types, type: :array, desc: 'tasks.common.options.types'