Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Got basic tasks like build and test working in external projects!
Browse files Browse the repository at this point in the history
Corrected a few mistakes, did a bit of cleanup, added a few useful hooks
for external plugins.
  • Loading branch information
nathankleyn committed Jan 17, 2015
1 parent 6419458 commit e983774
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 44 deletions.
1 change: 1 addition & 0 deletions Shantyfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 3 additions & 3 deletions lib/shanty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions lib/shanty/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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
Expand Down
18 changes: 0 additions & 18 deletions lib/shanty/discoverers/gradle.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/shanty/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion lib/shanty/mutators/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion lib/shanty/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,5 +67,13 @@ def inspect
options: options
}.inspect
end

private

def within_project_dir
Dir.chdir(path) do
yield
end
end
end
end
14 changes: 8 additions & 6 deletions lib/shanty/task_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ 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

def graph
@graph ||= construct_project_graph
end

private

def environment
@environment = ENV['SHANTY_ENV'] || 'local'
end
Expand All @@ -28,6 +28,8 @@ def root
@root ||= find_root
end

private

def config
return @config unless @config.nil?

Expand Down
3 changes: 2 additions & 1 deletion lib/shanty/task_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions lib/shanty/task_sets/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
Expand All @@ -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'
Expand Down

0 comments on commit e983774

Please sign in to comment.