gator 0.0.21.pre → 0.0.22.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/Gemfile +3 -1
  2. data/Rakefile +3 -6
  3. data/VERSION +1 -1
  4. data/bin/gator +2 -3
  5. data/gator.gemspec +52 -30
  6. data/lib/gator.rb +6 -8
  7. data/lib/gator/core.rb +19 -0
  8. data/lib/gator/core/application/application.rb +41 -0
  9. data/lib/gator/core/application/application_configuration.rb +11 -0
  10. data/lib/gator/core/command/act_as_command.rb +40 -0
  11. data/lib/gator/core/command/act_as_command_collection.rb +63 -0
  12. data/lib/gator/core/command/command.rb +20 -0
  13. data/lib/gator/{task.rb → core/command/task.rb} +1 -4
  14. data/lib/gator/core/configuration/act_as_configuration.rb +30 -0
  15. data/lib/gator/core/configuration/configuration.rb +5 -0
  16. data/lib/gator/core/io/paths.rb +21 -0
  17. data/lib/gator/core/io/project_file_locator.rb +28 -0
  18. data/lib/gator/core/io/ruby_file_loader.rb +21 -0
  19. data/lib/gator/core/io/sandbox.rb +9 -0
  20. data/lib/gator/{project.rb → core/project/layout.rb} +3 -44
  21. data/lib/gator/core/project/project.rb +21 -0
  22. data/lib/gator/plugins/generators.rb +5 -0
  23. data/lib/gator/{generators/generator.rb → plugins/generators/act_as_template_generator.rb} +1 -5
  24. data/lib/gator/{commands/generate.rb → plugins/generators/generate_command.rb} +1 -1
  25. data/lib/gator/plugins/generators/generator.rb +6 -0
  26. data/lib/gator/plugins/scaffolding.rb +4 -0
  27. data/lib/gator/plugins/scaffolding/scaffold_command.rb +62 -0
  28. data/lib/gator/plugins/scaffolding/scaffolding_file_utils.rb +58 -0
  29. data/rake/jeweler.rb +17 -0
  30. data/rake/jeweler_prerelease_tasks.rb +50 -0
  31. data/rake/pre_release_gemspec.rb +80 -0
  32. data/rake/pre_release_to_git.rb +59 -0
  33. data/spec/core/application/application_configuration_spec.rb +21 -0
  34. data/spec/core/application/application_spec.rb +15 -0
  35. data/spec/core/command/command_spec.rb +117 -0
  36. data/spec/core/command/task_spec.rb +95 -0
  37. data/spec/core/configuration/configuration_spec.rb +55 -0
  38. data/spec/core/io/paths_spec.rb +44 -0
  39. data/spec/core/io/sandbox_spec.rb +11 -0
  40. data/spec/core/project/layout_spec.rb +64 -0
  41. data/spec/core/project/project_spec.rb +51 -0
  42. data/spec/fixtures/empty_gator_project/gator.rb +4 -0
  43. data/spec/fixtures/no_gator_file/.empty_directory +0 -0
  44. data/spec/plugins/scaffolding/scaffold_command_spec.rb +75 -0
  45. data/spec/spec_helper.rb +14 -9
  46. metadata +65 -36
  47. data/lib/gator/command.rb +0 -109
  48. data/lib/gator/commands.rb +0 -5
  49. data/lib/gator/commands/project.rb +0 -87
  50. data/lib/gator/config.rb +0 -23
  51. data/lib/gator/generators.rb +0 -1
  52. data/lib/gator/runner.rb +0 -21
  53. data/lib/gator/util.rb +0 -91
  54. data/spec/command_spec.rb +0 -84
  55. data/spec/config_spec.rb +0 -14
  56. data/spec/project_spec.rb +0 -15
  57. data/spec/runner_spec.rb +0 -9
  58. data/spec/task_spec.rb +0 -8
  59. data/spec/util_spec.rb +0 -60
@@ -0,0 +1,28 @@
1
+ class Gator
2
+ require 'pathname'
3
+ class ProjectFileLocator
4
+
5
+ def project_files
6
+ ["gator", "gator.rb"]
7
+ end
8
+
9
+ def project_file_paths(dir)
10
+ project_files.collect { |f| File.join(dir, f) }
11
+ end
12
+
13
+ def find_project_dir path=Dir.getwd
14
+ file = find_project_file path
15
+ File.dirname file unless file.nil?
16
+ end
17
+
18
+ def find_project_file path=Dir.getwd
19
+ gatorfile = nil
20
+ Pathname.new(path).ascend do |dir|
21
+ gatorfile = project_file_paths(dir).map { |g| Dir[g] }.flatten.first
22
+ break unless gatorfile.nil? || File.directory?(gatorfile)
23
+ end
24
+ gatorfile
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ class Gator
2
+ class RubyFileLoader
3
+
4
+ def initialize sandbox
5
+ @sandbox = sandbox
6
+ end
7
+
8
+ def sandbox
9
+ @sandbox
10
+ end
11
+
12
+ def exec_file file
13
+ exec_code File.binread( file )
14
+ end
15
+
16
+ def exec_code code
17
+ sandbox.module_eval( code )
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class Gator
2
+ module Sandbox
3
+ def self.add_getter name, value
4
+ Gator::Sandbox.class.send :define_method, name do
5
+ value
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,45 +1,5 @@
1
- module Gator
2
- module Project
3
-
4
- def self.project
5
- @project
6
- end
7
-
8
- def self.project=(project)
9
- @project = project
10
- end
11
-
12
- def project(project= nil)
13
- Project.project = project unless project.nil?
14
- $stderr.puts "WARNING: No project definition found." if Project.project.nil?
15
- Project.project
16
- end
17
-
18
- class ProjectBase
19
-
20
- attr_accessor :name, :layout
21
-
22
- def initialize
23
- @name = ""
24
- @layout = Layout.default
25
- end
26
-
27
- def path(*args)
28
- File.join(Gator::Util.find_gator_project, layout.expand(*args))
29
- end
30
-
31
- def options
32
- @options ||= {}
33
- end
34
-
35
- def template_roots
36
- @template_roots ||= []
37
- end
38
-
39
- end
40
-
41
- # THIS CLASS IS STOLEN FROM BUILDR
42
-
1
+ class Gator
2
+ # THIS CLASS IS FROM BUILDR => buildr.apache.org
43
3
  # Symbolic mapping for directory layout. Used for both the default and custom layouts.
44
4
  #
45
5
  # For example, the default layout maps [:source, :main, :java] to 'src/main/java', and
@@ -125,5 +85,4 @@ module Gator
125
85
  self.default = Default.new
126
86
 
127
87
  end
128
- end
129
- end
88
+ end
@@ -0,0 +1,21 @@
1
+ class Gator
2
+ class Project
3
+ include Gator::ActAsConfiguration
4
+
5
+ attr_accessor :name, :layout
6
+
7
+ def initialize
8
+ @name = ""
9
+ @layout = Layout.default
10
+ end
11
+
12
+ def path(*args)
13
+ File.join( ProjectFileLocator.new.find_project_dir, layout.expand(*args) )
14
+ end
15
+
16
+ def template_roots
17
+ @template_roots ||= []
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/generators/generator'
2
+ require File.dirname(__FILE__) + '/generators/act_as_template_generator'
3
+ require File.dirname(__FILE__) + '/generators/generate_command'
4
+
5
+ Gator::Application << Gator::GenerateCommand
@@ -1,8 +1,4 @@
1
- module Gator
2
- class Generator < Task
3
- def init
4
- end
5
- end
1
+ class Gator
6
2
  module ActAsTemplateGenerator
7
3
 
8
4
  def self.included(base)
@@ -1,6 +1,6 @@
1
1
  require 'thor/actions'
2
2
 
3
- module Gator
3
+ class Gator
4
4
  class GenerateCommand < Command
5
5
  define :command => "generate", :short => "g",
6
6
  :usage => "generate TASK", :description => "Generators."
@@ -0,0 +1,6 @@
1
+ class Gator
2
+ class Generator < Task
3
+ def init
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/scaffolding/scaffolding_file_utils'
2
+ require File.dirname(__FILE__) + '/scaffolding/scaffold_command'
3
+
4
+ Gator::Application << Gator::Scaffolding::ScaffoldCommand
@@ -0,0 +1,62 @@
1
+ require "thor"
2
+ require "thor/actions"
3
+ require "fileutils"
4
+
5
+ class Gator
6
+ module Scaffolding
7
+ class ScaffoldCommand < Command
8
+ include Thor::Actions
9
+
10
+ define :command => "scaffold", :short => "s",
11
+ :usage => "scaffold TASK", :description => "Set of tasks to manage scaffold templates."
12
+
13
+ def self.source_root
14
+ Gator::Scaffolding::ScaffoldingFileUtils.new.scaffolds_home
15
+ end
16
+
17
+ desc "scaffold install NAME TEMPLATE_NAME", "Install a scaffold template."
18
+ def install(dir, name=nil)
19
+ file_util.install_scaffold dir, name
20
+ end
21
+
22
+ desc "scaffold uninstall TEMPLATE_NAME", "Uninstall a scaffold template."
23
+ def uninstall( scaffold )
24
+ file_util.delete_scaffold scaffold
25
+ end
26
+
27
+ desc "scaffold new NAME TEMPLATE_NAME", "Create a new scaffold by template."
28
+ def new(name, template)
29
+ @scaffold_name = name
30
+ directory file_util.scaffold_directory(template), File.expand_path(name)
31
+ end
32
+
33
+ desc "scaffold wipe", "Delete all scaffold templates."
34
+ def wipe
35
+ file_util.delete_all_scaffolds
36
+ end
37
+
38
+ desc "scaffold list [SEARCH]", "Lists scaffold templates."
39
+ def list(search=nil)
40
+ entries = file_util.scaffold_entries
41
+ entries = entries.select { |e| e.include?(search) } unless search.nil?
42
+ entries.each { |e| say " #{e}" }
43
+ say "No templates found.", :blue if entries.empty?
44
+ end
45
+
46
+ no_tasks {
47
+
48
+ def scaffold_name
49
+ @scaffold_name
50
+ end
51
+
52
+ }
53
+
54
+ private
55
+
56
+ def file_util
57
+ @_file_util ||= Gator::Scaffolding::ScaffoldingFileUtils.new
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,58 @@
1
+ require 'fileutils'
2
+
3
+ class Gator
4
+ module Scaffolding
5
+ class ScaffoldingFileUtils
6
+ include Thor::Actions
7
+
8
+ def scaffolds_home
9
+ File.join(Gator::Paths.gator_home, "scaffolds")
10
+ end
11
+
12
+ def scaffold_directory name
13
+ File.join(scaffolds_home, name)
14
+ end
15
+
16
+ def directory_entries dir, join= true
17
+ entries = Dir.entries dir
18
+ entries.delete(".")
19
+ entries.delete("..")
20
+ entries.collect! { |e| File.join(dir, e) } if join
21
+ entries
22
+ end
23
+
24
+ def last_directory_name dir
25
+ dir.split(File::PATH_SEPARATOR).last
26
+ end
27
+
28
+ def scaffold_entries join= false
29
+ directory_entries scaffolds_home, join
30
+ end
31
+
32
+ def create_empty_directory_files dir
33
+ Dir.glob(File.join(dir, "**", "*")).each { |f|
34
+ create_file File.join(f, ".empty_directory"), ".empty_directory" if File.directory?(f) && Dir.entries(f).length == 2
35
+ }
36
+ end
37
+
38
+ def install_scaffold from_dir, name=nil
39
+ name ||= last_directory_name from_dir
40
+ entries = directory_entries from_dir
41
+ install_dir = scaffold_directory(name)
42
+ #empty_directory install_dir
43
+ FileUtils.mkdir_p install_dir
44
+ FileUtils.cp_r entries, install_dir
45
+ create_empty_directory_files install_dir
46
+ end
47
+
48
+ def delete_scaffold name
49
+ FileUtils.rm_r scaffold_directory(name)
50
+ end
51
+
52
+ def delete_all_scaffolds
53
+ scaffold_entries.each { |scaffold| delete_scaffold(scaffold) }
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ class Jeweler
2
+ require File.dirname(__FILE__)+'/pre_release_to_git'
3
+ require File.dirname(__FILE__)+'/pre_release_gemspec'
4
+
5
+ def prerelease_to_git
6
+ Jeweler::Commands::PreReleaseToGit.build_for(self).run
7
+ end
8
+
9
+ def prerelease_gemspec
10
+ Jeweler::Commands::PreReleaseGemspec.build_for(self).run
11
+ end
12
+
13
+ def is_prerelease_version?
14
+ version.end_with? ".pre"
15
+ end
16
+
17
+ end
@@ -0,0 +1,50 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require File.dirname(__FILE__)+"/jeweler"
4
+
5
+ class Jeweler
6
+ class PrereleaseTasks < Rake::TaskLib
7
+ attr_accessor :jeweler
8
+
9
+ def initialize
10
+ yield self if block_given?
11
+
12
+ define
13
+ end
14
+
15
+ def jeweler
16
+ @jeweler ||= Rake.application.jeweler
17
+ end
18
+
19
+ def define
20
+ namespace :git do
21
+ desc "Tag and push prerelease to git. (happens by default with `rake prerelease`)"
22
+ task :prerelease do
23
+ jeweler.prerelease_to_git
24
+ end
25
+ end
26
+
27
+ namespace :gemspec do
28
+ desc "Regenerate and validate gemspec, and then commits and pushes to git on develop branch"
29
+ task :prerelease do
30
+ jeweler.prerelease_gemspec
31
+ end
32
+ end
33
+
34
+ desc "Verifies that it is a prerelease version."
35
+ task :is_prerelease_version => :version_required do
36
+ abort "it's not a prerelease version" unless jeweler.is_prerelease_version?
37
+ end
38
+
39
+ namespace :rubygems do
40
+ desc "Release gem to Gemcutter"
41
+ task :release => [:gemspec, :build] do
42
+ jeweler.release_gem_to_rubygems
43
+ end
44
+ end
45
+
46
+ desc "Make a prerelease to rubygems."
47
+ task :prerelease => [:is_prerelease_version, 'gemspec:prerelease', 'git:prerelease', 'rubygems:release']
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,80 @@
1
+ class Jeweler
2
+ module Commands
3
+ class PreReleaseGemspec
4
+ attr_accessor :gemspec, :version, :repo, :output, :gemspec_helper, :base_dir
5
+
6
+ def initialize(attributes = {})
7
+ self.output = $stdout
8
+
9
+ attributes.each_pair do |key, value|
10
+ send("#{key}=", value)
11
+ end
12
+ end
13
+
14
+ def run
15
+ unless clean_staging_area?
16
+ system "git status"
17
+ raise "Unclean staging area! Be sure to commit or .gitignore everything first. See `git status` above."
18
+ end
19
+
20
+ repo.checkout('develop')
21
+
22
+ regenerate_gemspec!
23
+ commit_gemspec! if gemspec_changed?
24
+
25
+ output.puts "Pushing develop to origin"
26
+ repo.push
27
+ end
28
+
29
+ def clean_staging_area?
30
+ # surprisingly simpler than ruby-git
31
+ `git ls-files --deleted --modified --others --exclude-standard` == ""
32
+ end
33
+
34
+ def commit_gemspec!
35
+ gemspec_gitpath = working_subdir.join(gemspec_helper.path)
36
+ repo.add(gemspec_gitpath.to_s)
37
+ output.puts "Committing #{gemspec_gitpath}"
38
+ repo.commit "Regenerate gemspec for version #{version}"
39
+ end
40
+
41
+ def regenerate_gemspec!
42
+ gemspec_helper.update_version(version)
43
+ gemspec_helper.write
44
+ end
45
+
46
+ def gemspec_changed?
47
+ # OMGHAX. ruby-git status always ends up being 'M', so let's do it a crazy way
48
+ system "git status -s #{working_subdir.join(gemspec_helper.path)} | grep #{working_subdir.join(gemspec_helper.path)} > /dev/null 2>/dev/null"
49
+ end
50
+
51
+ def gemspec_helper
52
+ @gemspec_helper ||= Jeweler::GemSpecHelper.new(self.gemspec, self.base_dir)
53
+ end
54
+
55
+ def working_subdir
56
+ return @working_subdir if @working_subdir
57
+ cwd = base_dir_path
58
+ @working_subdir = cwd.relative_path_from(Pathname.new(repo.dir.path))
59
+ @working_subdir
60
+ end
61
+
62
+ def base_dir_path
63
+ Pathname.new(base_dir).realpath
64
+ end
65
+
66
+ def self.build_for(jeweler)
67
+ command = self.new
68
+
69
+ command.base_dir = jeweler.base_dir
70
+ command.gemspec = jeweler.gemspec
71
+ command.version = jeweler.version
72
+ command.repo = jeweler.repo
73
+ command.output = jeweler.output
74
+ command.gemspec_helper = jeweler.gemspec_helper
75
+
76
+ command
77
+ end
78
+ end
79
+ end
80
+ end