lucidimagination-warbler 1.3.2.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Gemfile +16 -0
  2. data/History.txt +217 -0
  3. data/LICENSE.txt +26 -0
  4. data/Manifest.txt +92 -0
  5. data/README.txt +255 -0
  6. data/Rakefile +103 -0
  7. data/bin/warble +11 -0
  8. data/ext/JarMain.java +148 -0
  9. data/ext/WarMain.java +112 -0
  10. data/ext/WarblerJar.java +182 -0
  11. data/ext/WarblerJarService.java +18 -0
  12. data/lib/warbler.rb +33 -0
  13. data/lib/warbler/application.rb +86 -0
  14. data/lib/warbler/config.rb +223 -0
  15. data/lib/warbler/gems.rb +37 -0
  16. data/lib/warbler/jar.rb +253 -0
  17. data/lib/warbler/task.rb +183 -0
  18. data/lib/warbler/templates/bundler.erb +3 -0
  19. data/lib/warbler/templates/config.erb +1 -0
  20. data/lib/warbler/templates/jar.erb +5 -0
  21. data/lib/warbler/templates/rack.erb +1 -0
  22. data/lib/warbler/templates/rails.erb +1 -0
  23. data/lib/warbler/templates/war.erb +1 -0
  24. data/lib/warbler/traits.rb +107 -0
  25. data/lib/warbler/traits/bundler.rb +104 -0
  26. data/lib/warbler/traits/gemspec.rb +59 -0
  27. data/lib/warbler/traits/jar.rb +56 -0
  28. data/lib/warbler/traits/merb.rb +35 -0
  29. data/lib/warbler/traits/nogemspec.rb +42 -0
  30. data/lib/warbler/traits/rack.rb +33 -0
  31. data/lib/warbler/traits/rails.rb +62 -0
  32. data/lib/warbler/traits/war.rb +197 -0
  33. data/lib/warbler/version.rb +10 -0
  34. data/lib/warbler/war.rb +8 -0
  35. data/lib/warbler_jar.jar +0 -0
  36. data/spec/drb_helper.rb +41 -0
  37. data/spec/sample_bundler/Gemfile.lock +10 -0
  38. data/spec/sample_bundler/config.ru +0 -0
  39. data/spec/sample_jar/History.txt +6 -0
  40. data/spec/sample_jar/Manifest.txt +8 -0
  41. data/spec/sample_jar/README.txt +30 -0
  42. data/spec/sample_jar/lib/sample_jar.rb +6 -0
  43. data/spec/sample_jar/sample_jar.gemspec +40 -0
  44. data/spec/sample_jar/test/test_sample_jar.rb +8 -0
  45. data/spec/sample_war/app/controllers/application.rb +15 -0
  46. data/spec/sample_war/app/helpers/application_helper.rb +3 -0
  47. data/spec/sample_war/config/boot.rb +109 -0
  48. data/spec/sample_war/config/database.yml +19 -0
  49. data/spec/sample_war/config/environment.rb +67 -0
  50. data/spec/sample_war/config/environments/development.rb +17 -0
  51. data/spec/sample_war/config/environments/production.rb +25 -0
  52. data/spec/sample_war/config/environments/test.rb +22 -0
  53. data/spec/sample_war/config/initializers/inflections.rb +10 -0
  54. data/spec/sample_war/config/initializers/mime_types.rb +5 -0
  55. data/spec/sample_war/config/initializers/new_rails_defaults.rb +15 -0
  56. data/spec/sample_war/config/routes.rb +41 -0
  57. data/spec/sample_war/lib/tasks/utils.rake +0 -0
  58. data/spec/sample_war/public/404.html +30 -0
  59. data/spec/sample_war/public/422.html +30 -0
  60. data/spec/sample_war/public/500.html +30 -0
  61. data/spec/sample_war/public/favicon.ico +0 -0
  62. data/spec/sample_war/public/index.html +274 -0
  63. data/spec/sample_war/public/robots.txt +5 -0
  64. data/spec/spec_helper.rb +112 -0
  65. data/spec/warbler/application_spec.rb +95 -0
  66. data/spec/warbler/bundler_spec.rb +136 -0
  67. data/spec/warbler/config_spec.rb +130 -0
  68. data/spec/warbler/gems_spec.rb +40 -0
  69. data/spec/warbler/jar_spec.rb +718 -0
  70. data/spec/warbler/task_spec.rb +170 -0
  71. data/spec/warbler/traits_spec.rb +17 -0
  72. data/spec/warbler/war_spec.rb +14 -0
  73. data/warble.rb +142 -0
  74. data/web.xml.erb +32 -0
  75. metadata +198 -0
@@ -0,0 +1,183 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
+ # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
+ # This source code is available under the MIT license.
5
+ # See the file LICENSE.txt for details.
6
+ #++
7
+
8
+ require 'rake'
9
+ require 'rake/tasklib'
10
+ require 'warbler/config'
11
+ require 'warbler/jar'
12
+
13
+ module Warbler
14
+ # Warbler Rake task. Allows defining multiple configurations inside the same
15
+ # Rakefile by using different task names.
16
+ #
17
+ # To define multiple Warbler configurations in a single project, use
18
+ # code like the following in a Rakefile:
19
+ #
20
+ # Warbler::Task.new("war1", Warbler::Config.new do |config|
21
+ # config.jar_name = "war1"
22
+ # # ...
23
+ # end
24
+ # Warbler::Task.new("war2", Warbler::Config.new do |config|
25
+ # config.jar_name = "war2"
26
+ # # ...
27
+ # end
28
+ #
29
+ # With this setup, you can create two separate war files two
30
+ # different configurations by running <tt>rake war1 war2</tt>.
31
+ class Task < Rake::TaskLib
32
+ # Task name
33
+ attr_accessor :name
34
+
35
+ # Warbler::Config
36
+ attr_accessor :config
37
+
38
+ # Warbler::Jar
39
+ attr_accessor :jar
40
+
41
+ def initialize(name = nil, config = nil)
42
+ @config = config
43
+ if @config.nil? && File.exists?(Config::FILE)
44
+ @config = eval(File.open(Config::FILE) {|f| f.read})
45
+ end
46
+ @config ||= Config.new
47
+ unless @config.kind_of? Config
48
+ $stderr.puts "Warbler::Config not provided by override in initializer or #{Config::FILE}; using defaults"
49
+ @config = Config.new
50
+ end
51
+ @name = name || @config.jar_extension
52
+ @jar = Warbler::Jar.new
53
+ yield self if block_given?
54
+ define_tasks
55
+ end
56
+
57
+ # Deprecated: attr_accessor :war
58
+ alias war jar
59
+
60
+ private
61
+ def define_tasks
62
+ define_main_task
63
+ namespace name do
64
+ define_clean_task
65
+ define_compiled_task
66
+ define_files_task
67
+ define_jar_task
68
+ define_debug_task
69
+ define_config_task
70
+ define_pluginize_task
71
+ define_version_task
72
+ define_extra_tasks
73
+ end
74
+ end
75
+
76
+ def define_main_task
77
+ desc "Create the project #{config.jar_extension} file"
78
+ task @name do
79
+ unless @config.features.empty?
80
+ @config.features.each do |feature|
81
+ t = "#@name:#{feature}"
82
+ unless Rake.application.lookup(t)
83
+ $stderr.puts "unknown feature `#{feature}', ignoring"
84
+ next
85
+ end
86
+ Rake::Task[t].invoke
87
+ end
88
+ end
89
+ # Invoke this way so custom dependencies can be defined before
90
+ # the file find routine is run
91
+ ["#{@name}:files", "#{@name}:jar"].each do |t|
92
+ Rake::Task[t].invoke
93
+ end
94
+ end
95
+ end
96
+
97
+ def define_clean_task
98
+ desc "Remove the project #{config.jar_extension} file"
99
+ task "clean" do
100
+ rm_f "#{config.jar_name}.#{config.jar_extension}"
101
+ end
102
+ task "clear" => "#{name}:clean"
103
+ end
104
+
105
+ def define_compiled_task
106
+ task "compiled" do
107
+ jar.compile(config)
108
+ task @name do
109
+ rm_f config.compiled_ruby_files.map {|f| f.sub(/\.rb$/, '.class') }
110
+ end
111
+ end
112
+ end
113
+
114
+ def define_files_task
115
+ task "files" do
116
+ jar.apply(config)
117
+ end
118
+ end
119
+
120
+ def define_jar_task
121
+ task "jar" do
122
+ jar.create(config)
123
+ end
124
+ end
125
+
126
+ def define_debug_task
127
+ desc "Dump diagnostic information"
128
+ task "debug" => "files" do
129
+ require 'yaml'
130
+ puts config.dump
131
+ jar.files.each {|k,v| puts "#{k} -> #{String === v ? v : '<blob>'}"}
132
+ end
133
+ task "debug:includes" => "files" do
134
+ puts "", "included files:"
135
+ puts *war.app_filelist.include
136
+ end
137
+ task "debug:excludes" => "files" do
138
+ puts "", "excluded files:"
139
+ puts *war.app_filelist.exclude
140
+ end
141
+ end
142
+
143
+ def define_extra_tasks
144
+ @config.define_tasks
145
+ end
146
+
147
+ def define_config_task
148
+ task "config" do
149
+ if File.exists?(Warbler::Config::FILE) && ENV["FORCE"].nil?
150
+ puts "There's another bird sitting on my favorite branch"
151
+ puts "(file '#{Warbler::Config::FILE}' already exists. Pass argument FORCE=1 to override)"
152
+ elsif !File.directory?("config")
153
+ puts "I'm confused; my favorite branch is missing"
154
+ puts "(directory 'config' is missing)"
155
+ else
156
+ cp "#{Warbler::WARBLER_HOME}/warble.rb", Warbler::Config::FILE
157
+ end
158
+ end
159
+ end
160
+
161
+ def define_pluginize_task
162
+ task "pluginize" do
163
+ if !Dir["vendor/plugins/warbler*"].empty? && ENV["FORCE"].nil?
164
+ puts "I found an old nest in vendor/plugins; please trash it so I can make a new one"
165
+ puts "(directory vendor/plugins/warbler* exists)"
166
+ else
167
+ rm_rf FileList["vendor/plugins/warbler*"], :verbose => false
168
+ mkdir_p "vendor/plugins/warbler/tasks"
169
+ File.open("vendor/plugins/warbler/tasks/warbler.rake", "w") do |f|
170
+ f.puts "require 'warbler'"
171
+ f.puts "Warbler::Task.new"
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ def define_version_task
178
+ task "version" do
179
+ puts "Warbler version #{Warbler::VERSION}"
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_WITHOUT'] = '<%= config.bundle_without.join(':') %>'
2
+ ENV['BUNDLE_GEMFILE'] = '<%= config.bundler[:gemfile].basename %>'
3
+ <% if config.bundler[:frozen] %>ENV['BUNDLE_FROZEN'] = '1'<% end %>
@@ -0,0 +1 @@
1
+ WARBLER_CONFIG = <%= config.webxml ? config.webxml.context_params(false).inspect : '{}' %>
@@ -0,0 +1,5 @@
1
+ <% if config.relative_gem_path.empty? %>
2
+ ENV['GEM_HOME'] ||= File.expand_path('../..', __FILE__)
3
+ <% else %>
4
+ ENV['GEM_HOME'] ||= File.expand_path('../../<%= config.relative_gem_path %>', __FILE__)
5
+ <% end %>
@@ -0,0 +1 @@
1
+ ENV['RACK_ENV'] = '<%= (params = config.webxml.context_params; params['rack.env']) %>'
@@ -0,0 +1 @@
1
+ ENV['RAILS_ENV'] = '<%= config.webxml.rails.env %>'
@@ -0,0 +1 @@
1
+ ENV['GEM_HOME'] ||= $servlet_context.getRealPath('<%= config.gem_path %>')
@@ -0,0 +1,107 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
+ # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
+ # This source code is available under the MIT license.
5
+ # See the file LICENSE.txt for details.
6
+ #++
7
+
8
+ require 'stringio'
9
+
10
+ module Warbler
11
+ # Traits are project configuration characteristics that correspond
12
+ # to the framework or project layout. Each trait corresponds to a
13
+ # class in Warbler::Traits that contains baked-in knowledge about
14
+ # the kind of project and how it should be packed into the jar or
15
+ # war file.
16
+ module Traits
17
+ attr_accessor :traits
18
+
19
+ def initialize
20
+ @traits = auto_detect_traits
21
+ end
22
+
23
+ def auto_detect_traits
24
+ Traits.constants.map {|t| Traits.const_get(t)}.select {|tc| tc.detect? }.sort
25
+ end
26
+
27
+ def before_configure
28
+ trait_objects.each {|t| t.before_configure }
29
+ end
30
+
31
+ def after_configure
32
+ trait_objects.each {|t| t.after_configure }
33
+ end
34
+
35
+ def trait_objects
36
+ @trait_objects ||= @traits.map {|klass| klass.new(self) }
37
+ end
38
+
39
+ def update_archive(jar)
40
+ trait_objects.each {|t| t.update_archive(jar) }
41
+ end
42
+
43
+ def dump_traits
44
+ @trait_objects = nil
45
+ @traits.collect! {|t| t.name }
46
+ end
47
+ end
48
+
49
+ # Each trait class includes this module to receive shared functionality.
50
+ module Trait
51
+ module ClassMethods
52
+ def <=>(o)
53
+ requires?(o) ? 1 : (o.requires?(self) ? -1 : 0)
54
+ end
55
+
56
+ def requires?(t)
57
+ false
58
+ end
59
+ end
60
+
61
+ def self.included(base)
62
+ base.extend ClassMethods
63
+ end
64
+
65
+ attr_reader :config
66
+ def initialize(config)
67
+ @config = config
68
+ end
69
+
70
+ def before_configure
71
+ end
72
+
73
+ def after_configure
74
+ end
75
+
76
+ def update_archive(jar)
77
+ end
78
+
79
+ def add_init_load_path(path)
80
+ config.init_contents << StringIO.new("$LOAD_PATH.unshift __FILE__.sub(/!.*/, '!/#{path}')\n")
81
+ end
82
+
83
+ def add_main_rb(jar, bin_path)
84
+ jar.files['META-INF/main.rb'] = StringIO.new("load '#{bin_path}'")
85
+ end
86
+
87
+ def update_gem_path(default_gem_path)
88
+ if config.gem_path != default_gem_path
89
+ config.gem_path = "/#{config.gem_path}" unless config.gem_path =~ %r{^/}
90
+ sub_gem_path = config.gem_path[1..-1]
91
+ config.pathmaps.marshal_dump.keys.each do |pm|
92
+ config.pathmaps.send(pm).each {|p| p.sub!(default_gem_path[1..-1], sub_gem_path)}
93
+ end
94
+ config.webxml["gem"]["path"] = config.gem_path if config.webxml
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ require 'warbler/traits/jar'
101
+ require 'warbler/traits/war'
102
+ require 'warbler/traits/rails'
103
+ require 'warbler/traits/merb'
104
+ require 'warbler/traits/rack'
105
+ require 'warbler/traits/bundler'
106
+ require 'warbler/traits/gemspec'
107
+ require 'warbler/traits/nogemspec'
@@ -0,0 +1,104 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
+ # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
+ # This source code is available under the MIT license.
5
+ # See the file LICENSE.txt for details.
6
+ #++
7
+
8
+ module Warbler
9
+ module Traits
10
+ # The Bundler trait uses Bundler to determine gem dependencies to
11
+ # be added to the project.
12
+ class Bundler
13
+ include Trait
14
+
15
+ def self.detect?
16
+ File.exist?(ENV['BUNDLE_GEMFILE'] || "Gemfile")
17
+ end
18
+
19
+ def self.requires?(trait)
20
+ trait == Traits::War || trait == Traits::Jar
21
+ end
22
+
23
+ def before_configure
24
+ config.bundler = true
25
+ config.bundle_without = ["development", "test"]
26
+ end
27
+
28
+ def after_configure
29
+ add_bundler_gems if config.bundler
30
+ end
31
+
32
+ def add_bundler_gems
33
+ require 'bundler'
34
+ config.gems.clear
35
+ config.gem_dependencies = false # Bundler takes care of these
36
+ config.bundler = {}
37
+
38
+ bundler_specs.each do |spec|
39
+ # Bundler HAX -- fixup bad #loaded_from attribute in fake
40
+ # bundler gemspec from bundler/source.rb
41
+ if spec.name == "bundler"
42
+ full_gem_path = Pathname.new(spec.full_gem_path)
43
+ tries = 2
44
+ (full_gem_path = full_gem_path.dirname; tries -= 1) while tries > 0 && !full_gem_path.join('bundler.gemspec').exist?
45
+ spec.loaded_from = full_gem_path.to_s
46
+ end
47
+
48
+ case spec.source
49
+ when ::Bundler::Source::Git
50
+ config.bundler[:git_specs] ||= []
51
+ config.bundler[:git_specs] << spec
52
+ when ::Bundler::Source::Path
53
+ $stderr.puts("warning: Bundler `path' components are not currently supported.",
54
+ "The `#{spec.full_name}' component was not bundled.",
55
+ "Your application may fail to boot!")
56
+ else
57
+ config.gems << spec
58
+ end
59
+ end
60
+ config.bundler[:gemfile] = ::Bundler.default_gemfile
61
+ config.bundler[:lockfile] = ::Bundler.default_lockfile
62
+ config.bundler[:frozen] = ::Bundler.settings[:frozen]
63
+ config.excludes += [::Bundler.settings[:path]] if ::Bundler.settings[:path]
64
+ config.init_contents << "#{config.warbler_templates}/bundler.erb"
65
+ end
66
+
67
+ def update_archive(jar)
68
+ add_bundler_files(jar) if config.bundler
69
+ end
70
+
71
+ # Add Bundler Gemfiles and git repositories to the archive.
72
+ def add_bundler_files(jar)
73
+ pwd = Pathname.new(Dir.pwd)
74
+ gemfile = config.bundler[:gemfile].relative_path_from(pwd).to_s
75
+ lockfile = config.bundler[:lockfile].relative_path_from(pwd).to_s
76
+ jar.files[jar.apply_pathmaps(config, gemfile, :application)] = config.bundler[:gemfile].to_s
77
+ if File.exist?(lockfile)
78
+ jar.files[jar.apply_pathmaps(config, lockfile, :application)] = config.bundler[:lockfile].to_s
79
+ end
80
+ if config.bundler[:git_specs]
81
+ pathmap = "#{config.relative_gem_path}/bundler/gems/%p"
82
+ pathmap.sub!(%r{^/+}, '')
83
+ config.pathmaps.git = [pathmap]
84
+ config.bundler[:git_specs].each do |spec|
85
+ full_gem_path = Pathname.new(spec.full_gem_path)
86
+ FileList["#{full_gem_path.to_s}/**/*"].each do |src|
87
+ f = Pathname.new(src).relative_path_from(full_gem_path).to_s
88
+ next if config.gem_excludes && config.gem_excludes.any? {|rx| f =~ rx }
89
+ jar.files[jar.apply_pathmaps(config, File.join(full_gem_path.basename, f), :git)] = src
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def bundler_specs
98
+ bundle_without = config.bundle_without.map {|s| s.to_sym}
99
+ definition = ::Bundler.definition
100
+ definition.specs_for(definition.groups - bundle_without)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,59 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 Engine Yard, Inc.
3
+ # Copyright (c) 2007-2009 Sun Microsystems, Inc.
4
+ # This source code is available under the MIT license.
5
+ # See the file LICENSE.txt for details.
6
+ #++
7
+
8
+ module Warbler
9
+ module Traits
10
+ # The Gemspec trait reads a .gemspec file to determine the files,
11
+ # executables, require paths, and dependencies for a project.
12
+ class Gemspec
13
+ include Trait
14
+
15
+ def self.detect?
16
+ !Dir['*.gemspec'].empty?
17
+ end
18
+
19
+ def before_configure
20
+ @spec_file = Dir['*.gemspec'].first
21
+ require 'yaml'
22
+ @spec = File.open(@spec_file) {|f| Gem::Specification.from_yaml(f) } rescue Gem::Specification.load(@spec_file)
23
+ @spec.runtime_dependencies.each {|g| config.gems << g }
24
+ config.dirs = []
25
+ config.compiled_ruby_files = @spec.files.select {|f| f =~ /\.rb$/}
26
+ end
27
+
28
+ def after_configure
29
+ @spec.require_paths.each do |p|
30
+ add_init_load_path(config.pathmaps.application.inject(p) {|pm,x| pm.pathmap(x)})
31
+ end
32
+ end
33
+
34
+ def update_archive(jar)
35
+ (Dir['**/*'] - config.compiled_ruby_files).each do |f|
36
+ jar.files[jar.apply_pathmaps(config, f, :application)] = f
37
+ end
38
+ config.compiled_ruby_files.each do |f|
39
+ f = f.sub(/\.rb$/, '.class')
40
+ next unless File.exist?(f)
41
+ jar.files[jar.apply_pathmaps(config, f, :application)] = f
42
+ end
43
+ bin_path = jar.apply_pathmaps(config, default_executable, :application)
44
+ add_main_rb(jar, bin_path)
45
+ end
46
+
47
+ def default_executable
48
+ if !@spec.executables.empty?
49
+ "bin/#{@spec.executables.first}"
50
+ else
51
+ exe = Dir['bin/*'].first
52
+ raise "No executable script found" unless exe
53
+ warn "No default executable found in #{@spec_file}, using #{exe}"
54
+ exe
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end