This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change tracking, env class, removed VCS code. Bump to v0.2.
- Loading branch information
1 parent
7f49d08
commit 37439f7
Showing
17 changed files
with
169 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
*.gem | ||
coverage | ||
.shanty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
## v0.2.0 (22nd January, 2015) | ||
|
||
* **Change tracking:** Added working changed flags to projects to allow CLI tasks to run just on projects that are different since last time. Note that this is a work in progress, as there are lots of things to still work on here (for example, it's currently implemented as a mutator, and it saves the change index even if the CLI command doesn't end up using it or fails to run). | ||
* **Env class:** Added Env class to allow passing around of config, paths and other stuff separate to the TaskEnv (which contains the graph). An env instance is available to all mutators and discovers. TaskEnv is just a decorator of Env, so you can continue to call the methods you used to on it where you only have TaskEnv available (eg. in a task)! | ||
* **Removed VCS/Git Code:** Now that we have change support that doesn't need a VCS, all of the VCS and Git stuff has been removed. This was all internal for now anyway, so shouldn't effect anybody. However, this does mean you can now use Shanty in any directory, rather than it having to be a VCS repository of some sort. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
shanty (0.1.0) | ||
shanty (0.2.0) | ||
algorithms (~> 0.6) | ||
commander (~> 4.2) | ||
deep_merge (~> 1.0) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'deep_merge' | ||
require 'yaml' | ||
|
||
module Shanty | ||
# | ||
class Env | ||
CONFIG_FILE = '.shanty.yml' | ||
DEFAULT_CONFIG = {} | ||
|
||
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 environment | ||
@environment = ENV['SHANTY_ENV'] || 'local' | ||
end | ||
|
||
def root | ||
@root ||= find_root | ||
end | ||
|
||
private | ||
|
||
def config | ||
return @config unless @config.nil? | ||
|
||
file_config = YAML.load_file("#{root}/#{CONFIG_FILE}") || {} | ||
@config = DEFAULT_CONFIG.deep_merge!(file_config[environment]) | ||
end | ||
|
||
def find_root | ||
if root_dir.nil? | ||
fail "Could not find a #{CONFIG_FILE} file in this or any parent directories. \ | ||
Please run `shanty init` in the directory you want to be the root of your project structure." | ||
end | ||
|
||
root_dir | ||
end | ||
|
||
def root_dir | ||
Pathname.new(Dir.pwd).ascend do |d| | ||
return d if d.join(CONFIG_FILE).exist? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require 'find' | ||
require 'fileutils' | ||
require 'set' | ||
require 'shanty/mutator' | ||
|
||
module Shanty | ||
# Mutates the graph to mark projects which have changed since the last time they were built. | ||
class ChangedMutator < Mutator | ||
UNIT_SEPARATOR = "\u001F" | ||
|
||
def mutate | ||
FileUtils.mkdir(shanty_dir) unless File.directory?(shanty_dir) | ||
|
||
self.cached_index = all_index_files.each_with_object({}) do |path, acc| | ||
# Check if the file has changed between | ||
next if unchanged_in_index?(path) | ||
# Otherwise, it was modified, deleted or added, so update the index if the file still exists. | ||
acc[path] = current_index[path] if current_index.include?(path) | ||
mark_project_as_changed(path) | ||
end | ||
end | ||
|
||
private | ||
|
||
def shanty_dir | ||
File.join(env.root, '.shanty') | ||
end | ||
|
||
def index_file | ||
File.join(shanty_dir, 'index') | ||
end | ||
|
||
def all_index_files | ||
Set.new(cached_index.keys + current_index.keys).to_a | ||
end | ||
|
||
def cached_index | ||
return @cached_index unless @cached_index.nil? | ||
return (@cached_index = {}) unless File.exist?(index_file) | ||
|
||
@cached_index = File.open(index_file).each_line.each_with_object({}) do |line, acc| | ||
path, *attrs = line.split(UNIT_SEPARATOR) | ||
acc[path] = attrs | ||
end | ||
end | ||
|
||
def cached_index=(new_index) | ||
File.open(index_file, 'w+') do |f| | ||
new_index.each do |path, attrs| | ||
f.puts(attrs.unshift(path).join(UNIT_SEPARATOR)) | ||
end | ||
end | ||
end | ||
|
||
def unchanged_in_index?(path) | ||
cached = cached_index[path] | ||
current = current_index[path] | ||
!cached.nil? && !current.nil? && current == cached | ||
end | ||
|
||
def current_index | ||
@current_index ||= Find.find(env.root).each_with_object({}) do |path, acc| | ||
# FIXME: Pass in list of excludes and match as follows: | ||
# next Find.prune if path =~ /(build|.git|.gradle)/ | ||
next unless File.exist?(path) | ||
s = File.stat(path) | ||
next if s.directory? | ||
|
||
acc[path] = [s.mtime.to_i, s.size] | ||
end | ||
end | ||
|
||
def mark_project_as_changed(path) | ||
project = graph.owner_of_file(File.join(env.root, path)) | ||
project.changed = true unless project.nil? | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.