warbler 0.9

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,7 @@
1
+ == 0.9
2
+
3
+ * Birthday! Warbler is a gem to make a .war file out of a Rails project. The intent is to provide a
4
+ minimal, flexible, ruby-like way to bundle up all of your application files for deployment to a
5
+ Java application server.
6
+ * Bundled versions: goldspike-1.4-SNAPSHOT and jruby-complete-1.0.1
7
+ * Works as both a gem (rake application) or a plugin
data/LICENSES.txt ADDED
@@ -0,0 +1,35 @@
1
+ = Warbler
2
+
3
+ Warbler is provided under the terms of the MIT license.
4
+
5
+ (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
6
+
7
+ Permission is hereby granted, free of charge, to any person
8
+ obtaining a copy of this software and associated documentation files
9
+ (the "Software"), to deal in the Software without restriction,
10
+ including without limitation the rights to use, copy, modify, merge,
11
+ publish, distribute, sublicense, and/or sell copies of the Software,
12
+ and to permit persons to whom the Software is furnished to do so,
13
+ subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ = Additional Bundled Software
28
+
29
+ Goldspike (goldspike-*.jar) is distributed under the terms of the MIT license. See http://jruby-extras.rubyforge.org/svn/trunk/rails-integration/LICENSE.txt for details.
30
+
31
+ JRuby (jruby-complete-*.jar) is distrubuted under the terms of the Common Public License. See http://www.eclipse.org/legal/cpl-v10.html for details. At your option, JRuby is also available under the GPL or LGPL licenses. See the file COPYING in the JRuby distribution for details (http://svn.codehaus.org/jruby/trunk/jruby/COPYING).
32
+
33
+ JavaBeans Activation Framework (activation-*.jar) is distributed under the terms of the Common Development and Distribution License (CDDL) v1.0, see http://www.sun.com/cddl/cddl.html for details.
34
+
35
+ Commons-pool (commons-pool-*.jar) is distributed under the terms of the Apache Software License, version 2.0. See http://www.apache.org/licenses/LICENSE-2.0 for details.
data/Manifest.txt ADDED
@@ -0,0 +1,24 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ LICENSES.txt
5
+ Rakefile
6
+ web.xml.erb
7
+ bin/warble
8
+ generators/warble
9
+ generators/warble/templates
10
+ generators/warble/templates/warble.rb
11
+ generators/warble/warble_generator.rb
12
+ lib/activation-1.1.jar
13
+ lib/commons-pool-1.3.jar
14
+ lib/goldspike-1.4-SNAPSHOT.jar
15
+ lib/jruby-complete-1.0.1.jar
16
+ lib/warbler
17
+ lib/warbler/config.rb
18
+ lib/warbler/task.rb
19
+ lib/warbler/version.rb
20
+ lib/warbler.rb
21
+ spec/spec_helper.rb
22
+ spec/warbler/config_spec.rb
23
+ spec/warbler/task_spec.rb
24
+ tasks/warbler.rake
data/README.txt ADDED
@@ -0,0 +1,84 @@
1
+ = Warbler
2
+
3
+ Warbler is a gem to make a .war file out of a Rails project. The intent is to provide a minimal,
4
+ flexible, ruby-like way to bundle up all of your application files for deployment to a Java
5
+ application server.
6
+
7
+ Warbler provides a sane set of out-of-the box defaults that should allow most Rails applications
8
+ without external gem dependencies (aside from Rails itself) to assemble and Just Work.
9
+
10
+ Warbler bundles JRuby and the Goldspike servlet for dispatching requests to your application inside
11
+ the java application server, and assembles all jar files in WARBLER_HOME/lib/*.jar into
12
+ your application. No external dependencies are downloaded.
13
+
14
+ == Getting Started
15
+
16
+ 1. Install the gem: <tt>gem install warbler</tt>.
17
+ 2. Run warbler in the top directory of your Rails application: <tt>warble</tt>.
18
+ 3. Deploy your railsapp.war file to your favorite Java application server.
19
+
20
+ == Usage
21
+
22
+ Warbler's +warble+ command is just a small wrapper around Rake with internally defined tasks. (Notice
23
+ "rake" still prints out in the message, but you should substitute "warble" for "rake" on the command
24
+ line when running this way.)
25
+
26
+ $ warble -T
27
+ rake config # Generate a configuration file to customize your war assembly
28
+ rake pluginize # Unpack warbler as a plugin in your Rails application
29
+ rake war # Create trunk.war
30
+ rake war:app # Copy all application files into the .war
31
+ rake war:clean # Clean up the .war file and the staging area
32
+ rake war:gems # Unpack all gems into WEB-INF/gems
33
+ rake war:jar # Run the jar command to create the .war
34
+ rake war:java_libs # Copy all java libraries into the .war
35
+ rake war:public # Copy all public HTML files to the root of the .war
36
+ rake war:webxml # Generate a web.xml file for the webapp
37
+
38
+ Warble makes heavy use of Rake's file and directory tasks, so only recently updated files will be
39
+ copied, making repeated assemblies much faster.
40
+
41
+ == Configuration
42
+
43
+ The default configuration puts application files (+app+, +config+, +lib+, +log+, +vendor+, +tmp+)
44
+ under the .war file's WEB-INF directory, and files in +public+ in the root of the .war file. Any Java
45
+ .jar files stored in lib will automatically be placed in WEB-INF/lib for placement on the web app's
46
+ classpath.
47
+
48
+ To customize files, libraries, and gems included in the .war file, you'll need a config/warble.rb
49
+ file. There a two ways of doing this. With the gem, simply run
50
+
51
+ warble config
52
+
53
+ If you have Warbler installed as a plugin, use the generator:
54
+
55
+ script/generate warble
56
+
57
+ Finally, edit the config/warble.rb to your taste. If you install the gem but later decide you'd like to have it as a plugin, use the +pluginize+ command:
58
+
59
+ warble pluginize
60
+
61
+ If you wish to upgrade or switch one or more java libraries from what's bundled in the Warbler gem, simply change the jars in WARBLER_HOME/lib, or modify the +java_libs+ attribute of Warbler::Config to include the files you need.
62
+
63
+ Once Warbler is installed as a plugin, you can use +rake+ to build the war (with the same set of tasks as above).
64
+
65
+ For more information on configuration, see Warbler::Config.
66
+
67
+ === Caveats
68
+
69
+ Warbler requires that RAILS_ROOT will effectively be set to /WEB-INF when running inside the war, while the application public files will be in the root directory. The purpose is to make the application structure match the Java webapp archive structure, where WEB-INF is a protected directory not visible to the web server. Because of this change, features of Rails that expect the public assets directory to live in RAILS_ROOT/public may not function properly. However, we feel that the added security of conforming to the webapp structure is worth these minor inconveniences.
70
+
71
+ For Rails 1.2.3, the items that may need your attention are:
72
+
73
+ * Page caching will not work unless you set <tt>ActionController::Base.page_cache_directory = "#{RAILS_ROOT}/.."</tt>
74
+ * Asset tag timestamp calculation (e.g., <tt>javascripts/prototype.js?1188482864</tt>) will not happen. The workaround is to control this manually by setting the RAILS_ASSET_ID environment variable.
75
+ * Automatic inclusion of <tt>application.js</tt> through <tt>javascript_include_tag :defaults</tt> will not work. The workaround is to include it yourself with <tt>javascript_include_tag "application"</tt>.
76
+
77
+ == License
78
+
79
+ Warbler is provided under the terms of the MIT license.
80
+
81
+ Warbler (c) 2007 Nick Sieger <nicksieger@gmail.com>.
82
+
83
+ Warbler also bundles several other pieces of software. Please read the file LICENSES.txt to ensure
84
+ that you agree with the terms of all the components.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'spec/rake/spectask'
2
+
3
+ MANIFEST = FileList["History.txt", "Manifest.txt", "README.txt", "LICENSES.txt", "Rakefile",
4
+ "*.erb", "bin/*", "generators/**/*", "lib/**/*", "spec/**/*.rb", "tasks/**/*.rake"]
5
+
6
+ begin
7
+ File.open("Manifest.txt", "w") {|f| MANIFEST.each {|n| f << "#{n}\n"} }
8
+ require 'hoe'
9
+ require File.dirname(__FILE__) + '/lib/warbler/version'
10
+ hoe = Hoe.new("warbler", Warbler::VERSION) do |p|
11
+ p.rubyforge_name = "caldersphere"
12
+ p.url = "http://caldersphere.rubyforge.org/warbler"
13
+ p.author = "Nick Sieger"
14
+ p.email = "nick@nicksieger.com"
15
+ p.summary = "Warbler chirpily constructs .war files of your Rails applications."
16
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
17
+ p.description = p.paragraphs_of('README.txt', 0...1).join("\n\n")
18
+ p.extra_deps.reject!{|d| d.first == "hoe"}
19
+ p.test_globs = ["spec/**/*_spec.rb"]
20
+ p.rdoc_pattern = /\.(rb|txt)/
21
+ end
22
+ hoe.spec.files = MANIFEST
23
+ hoe.spec.dependencies.delete_if { |dep| dep.name == "hoe" }
24
+ rescue LoadError
25
+ puts "You really need Hoe installed to be able to package this gem"
26
+ end
27
+
28
+ # Hoe insists on setting task :default => :test
29
+ # !@#$ no easy way to empty the default list of prerequisites
30
+ Rake::Task['default'].send :instance_variable_set, "@prerequisites", FileList[]
31
+
32
+ task :default => :spec
33
+
34
+ Spec::Rake::SpecTask.new do |t|
35
+ t.spec_opts ||= []
36
+ t.spec_opts << "--diff" << "unified"
37
+ end
data/bin/warble ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #--
4
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
5
+ # See the file LICENSES.txt included with the distribution for
6
+ # software license details.
7
+ #++
8
+
9
+ require 'rubygems'
10
+ require 'rake'
11
+ require 'warbler'
12
+
13
+ application = Rake.application
14
+ application.standard_exception_handling do
15
+ application.init
16
+
17
+ Warbler::Task.new
18
+
19
+ task :default => :war
20
+
21
+ desc "Generate a configuration file to customize your war assembly"
22
+ task :config do
23
+ if File.exists?(Warbler::Config::FILE) && ENV["FORCE"].nil?
24
+ warn "#{Warbler::Config::FILE}: file already exists. Use FORCE=1 to override"
25
+ else
26
+ cp "#{Warbler::WARBLER_HOME}/generators/warble/templates/warble.rb", Warbler::Config::FILE
27
+ end
28
+ end
29
+
30
+ desc "Unpack warbler as a plugin in your Rails application"
31
+ task :pluginize do
32
+ unless Dir["vendor/plugins/warbler*"].empty?
33
+ warn "warbler is already installed as a plugin; please remove before re-installing"
34
+ else
35
+ Dir.chdir("vendor/plugins") do
36
+ ruby "-S", "gem", "unpack", "warbler"
37
+ end
38
+ end
39
+ end
40
+
41
+ application.top_level
42
+ end
@@ -0,0 +1,52 @@
1
+ # Warbler web application assembly configuration file
2
+ Warbler::Config.new do |config|
3
+ # Temporary directory where the application is staged
4
+ # config.staging_dir = "tmp/war"
5
+
6
+ # Application directories to be included in the webapp.
7
+ config.dirs = %w(app config lib log vendor tmp)
8
+
9
+ # Additional files/directories to include, above those in config.dirs
10
+ # config.includes = FileList["db"]
11
+
12
+ # Additional files/directories to exclude
13
+ # config.excludes = FileList["lib/tasks/*"]
14
+
15
+ # Additional Java .jar files to include. Note that if .jar files are placed
16
+ # in lib (and not otherwise excluded) then they need not be mentioned here
17
+ # config.java_libs = FileList["lib/java/*.jar"]
18
+ # config.java_libs << "lib/java/*.jar"
19
+
20
+ # External gems to be packaged in the webapp.
21
+ # config.gems = ["ActiveRecord-JDBC", "jruby-openssl"]
22
+ # config.gems << "tzinfo"
23
+
24
+ # Include gem dependencies not mentioned specifically
25
+ config.gem_dependencies = true
26
+
27
+ # Files to be included in the root of the webapp
28
+ # config.public_html = FileList["public/**/*", "doc/**/*"]
29
+
30
+ # Name of the war file (without the .war) -- defaults to the basename
31
+ # of RAILS_ROOT
32
+ # config.war_name = "mywar"
33
+
34
+ # True if the webapp has no external dependencies
35
+ config.webxml.standalone = true
36
+
37
+ # Location of JRuby, required for non-standalone apps
38
+ # config.webxml.jruby_home = <jruby/home>
39
+
40
+ # Value of RAILS_ENV for the webapp
41
+ config.webxml.rails_env = 'production'
42
+
43
+ # Control the pool of Rails runtimes
44
+ # (Goldspike-specific; see README for details)
45
+ # config.webxml.pool.maxActive = 4
46
+ # config.webxml.pool.minIdle = 2
47
+ # config.webxml.pool.checkInterval = 0
48
+ # config.webxml.pool.maxWait = 30000
49
+
50
+ # JNDI data source name
51
+ # config.webxml.jndi = 'jdbc/rails'
52
+ end
@@ -0,0 +1,19 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ class WarbleGenerator < Rails::Generator::Base
8
+ def manifest
9
+ record do |m|
10
+ m.directory 'config'
11
+ m.template 'warble.rb', File.join('config', 'warble.rb')
12
+ end
13
+ end
14
+
15
+ protected
16
+ def banner
17
+ "Usage: #{$0} warble"
18
+ end
19
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,112 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ require 'ostruct'
8
+
9
+ module Warbler
10
+ # Warbler assembly configuration.
11
+ class Config
12
+ TOP_DIRS = %w(app config lib log vendor tmp)
13
+ FILE = "config/warble.rb"
14
+
15
+ # Directory where files will be staged, defaults to tmp/war
16
+ attr_accessor :staging_dir
17
+
18
+ # Top-level directories to be copied into WEB-INF. Defaults to
19
+ # names in TOP_DIRS
20
+ attr_accessor :dirs
21
+
22
+ # Additional files beyond the top-level directories to include in the
23
+ # WEB-INF directory
24
+ attr_accessor :includes
25
+
26
+ # Files to exclude from the WEB-INF directory
27
+ attr_accessor :excludes
28
+
29
+ # Java libraries to copy to WEB-INF/lib
30
+ attr_accessor :java_libs
31
+
32
+ # Rubygems to install into the webapp at WEB-INF/gems
33
+ attr_accessor :gems
34
+
35
+ # Whether to include dependent gems (default true)
36
+ attr_accessor :gem_dependencies
37
+
38
+ # Public HTML directory file list, to be copied into the root of the war
39
+ attr_accessor :public_html
40
+
41
+ # Name of war file (without the .war), defaults to the directory name containing
42
+ # the Rails application
43
+ attr_accessor :war_name
44
+
45
+ # Extra configuration for web.xml/goldspike. These options are particular
46
+ # to Goldspike's Rails servlet and web.xml file.
47
+ #
48
+ # * <tt>webxml.standalone</tt> -- whether the .war file is "standalone",
49
+ # meaning JRuby, all java and gem dependencies are completely embedded
50
+ # in file. One of +true+ (default) or +false+.
51
+ # * <tt>webxml.jruby_home</tt> -- required if standalone is false. The
52
+ # directory containing the JRuby installation to use when the app is
53
+ # running.
54
+ # * <tt>webxml.rails_env</tt> -- the Rails environment to use for the
55
+ # running application, usually either development or production (the
56
+ # default).
57
+ # * <tt>webxml.pool.maxActive</tt> -- maximum number of pooled Rails
58
+ # application runtimes (default 4)
59
+ # * <tt>webxml.pool.minIdle</tt> -- minimum number of pooled runtimes to
60
+ # keep around during idle time (default 2)
61
+ # * <tt>webxml.pool.checkInterval</tt> -- how often to check whether the
62
+ # pool size is within minimum and maximum limits, in milliseconds
63
+ # (default 0)
64
+ # * <tt>webxml.pool.maxWait</tt> -- how long a waiting thread should wait
65
+ # for a runtime before giving up, in milliseconds (default 30000)
66
+ # * <tt>webxml.jndi</tt> -- the name of a JNDI data source name to be
67
+ # available to the application
68
+ # * <tt>webxml.servlet_name</tt> -- the name of the servlet to receive all
69
+ # requests. One of +files+ or +rails+. Goldspike's default behavior is
70
+ # to route first through the FileServlet, and if the file isn't found,
71
+ # it is forwarded to the RailsServlet. Use +rails+ if your application
72
+ # server is fronted by Apache or something else that will handle static
73
+ # files.
74
+ attr_accessor :webxml
75
+
76
+ def initialize
77
+ @staging_dir = "tmp/war"
78
+ @dirs = TOP_DIRS
79
+ @includes = FileList[]
80
+ @excludes = FileList["#{WARBLER_HOME}/**/*"]
81
+ @java_libs = FileList["#{WARBLER_HOME}/lib/*.jar"]
82
+ @gems = default_gems
83
+ @gem_dependencies = true
84
+ @public_html = FileList["public/**/*"]
85
+ @webxml = default_webxml_config
86
+ @war_name = if defined?(RAILS_ROOT)
87
+ File.basename(File.expand_path(RAILS_ROOT))
88
+ else
89
+ File.basename(File.expand_path(Dir.getwd))
90
+ end
91
+ yield self if block_given?
92
+ @excludes << @staging_dir
93
+ end
94
+
95
+ def gem_target_path
96
+ "#{@staging_dir}/WEB-INF/gems"
97
+ end
98
+
99
+ private
100
+ def default_webxml_config
101
+ c = OpenStruct.new
102
+ c.standalone = true
103
+ c.rails_env = "production"
104
+ c.pool = OpenStruct.new
105
+ c
106
+ end
107
+
108
+ def default_gems
109
+ File.directory?("vendor/rails") ? [] : ["rails"]
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,223 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ require 'rake'
8
+ require 'rake/tasklib'
9
+
10
+ module Warbler
11
+ # Warbler Rake task. Allows defining multiple configurations inside the same
12
+ # Rakefile by using different task names.
13
+ class Task < Rake::TaskLib
14
+ COPY_PROC = proc {|t| cp t.prerequisites.last, t.name }
15
+
16
+ # Task name
17
+ attr_accessor :name
18
+
19
+ # Warbler::Config
20
+ attr_accessor :config
21
+
22
+ # Whether to print a line when a file or directory task is declared; helps
23
+ # to see what is getting included
24
+ attr_accessor :verbose
25
+
26
+ def initialize(name = :war, config = nil, tasks = :define_tasks)
27
+ @name = name
28
+ @config = config
29
+ if @config.nil? && File.exists?(Config::FILE)
30
+ @config = eval(File.open(Config::FILE) {|f| f.read})
31
+ end
32
+ @config ||= Config.new
33
+ unless @config.kind_of? Config
34
+ warn "War::Config not provided by override in initializer or #{Config::FILE}; using defaults"
35
+ @config = Config.new
36
+ end
37
+ yield self if block_given?
38
+ send tasks
39
+ end
40
+
41
+ private
42
+ def define_tasks
43
+ define_main_task
44
+ define_clean_task
45
+ define_public_task
46
+ define_gems_task
47
+ define_webxml_task
48
+ define_app_task
49
+ define_jar_task
50
+ define_debug_task
51
+ end
52
+
53
+ def define_main_task
54
+ desc "Create #{@config.war_name}.war"
55
+ task @name => ["#{@name}:app", "#{@name}:public", "#{@name}:webxml", "#{@name}:jar"]
56
+ end
57
+
58
+ def define_clean_task
59
+ with_namespace_and_config do |name, config|
60
+ desc "Clean up the .war file and the staging area"
61
+ task "clean" do
62
+ rm_rf config.staging_dir
63
+ rm_f "#{config.war_name}.war"
64
+ end
65
+ task "clear" => "#{name}:clean"
66
+ end
67
+ end
68
+
69
+ def define_public_task
70
+ public_target_files = define_public_file_tasks
71
+ with_namespace_and_config do
72
+ desc "Copy all public HTML files to the root of the .war"
73
+ task "public" => public_target_files
74
+ end
75
+ end
76
+
77
+ def define_gems_task
78
+ directory "#{@config.gem_target_path}/gems"
79
+ targets = define_copy_gems_tasks
80
+ with_namespace_and_config do
81
+ desc "Unpack all gems into WEB-INF/gems"
82
+ task "gems" => targets
83
+ end
84
+ end
85
+
86
+ def define_webxml_task
87
+ with_namespace_and_config do |name, config|
88
+ desc "Generate a web.xml file for the webapp"
89
+ task "webxml" do
90
+ mkdir_p "#{config.staging_dir}/WEB-INF"
91
+ if File.exist?("config/web.xml")
92
+ cp "config/web.xml", "#{config.staging_dir}/WEB-INF"
93
+ else
94
+ erb = if File.exist?("config/web.xml.erb")
95
+ "config/web.xml.erb"
96
+ else
97
+ "#{WARBLER_HOME}/web.xml.erb"
98
+ end
99
+ require 'erb'
100
+ erb = ERB.new(File.open(erb) {|f| f.read })
101
+ File.open("#{config.staging_dir}/WEB-INF/web.xml", "w") do |f|
102
+ f << erb.result(erb_binding(config.webxml))
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ def define_java_libs_task
110
+ target_files = @config.java_libs.map do |lib|
111
+ define_file_task(lib,
112
+ "#{@config.staging_dir}/WEB-INF/lib/#{File.basename(lib)}")
113
+ end
114
+ with_namespace_and_config do |name, config|
115
+ desc "Copy all java libraries into the .war"
116
+ task "java_libs" => target_files
117
+ end
118
+ target_files
119
+ end
120
+
121
+ def define_app_task
122
+ webinf_target_files = define_webinf_file_tasks
123
+ with_namespace_and_config do |name, config|
124
+ desc "Copy all application files into the .war"
125
+ task "app" => ["#{name}:gems", *webinf_target_files]
126
+ end
127
+ end
128
+
129
+ def define_jar_task
130
+ with_namespace_and_config do |name, config|
131
+ desc "Run the jar command to create the .war"
132
+ task "jar" do
133
+ sh "jar", "cf", "#{config.war_name}.war", "-C", config.staging_dir, "."
134
+ end
135
+ end
136
+ end
137
+
138
+ def define_debug_task
139
+ with_namespace_and_config do |name, config|
140
+ task "debug" do
141
+ require 'pp'
142
+ pp config
143
+ end
144
+ end
145
+ end
146
+
147
+ def define_public_file_tasks
148
+ @config.public_html.map do |f|
149
+ define_file_task(f, "#{@config.staging_dir}/#{f.sub(%r{public/},'')}")
150
+ end
151
+ end
152
+
153
+ def define_webinf_file_tasks
154
+ files = FileList[*@config.dirs.map{|d| "#{d}/**/*"}]
155
+ files.include(*@config.includes.to_a)
156
+ files.exclude(*@config.excludes.to_a)
157
+ target_files = files.map do |f|
158
+ define_file_task(f, "#{@config.staging_dir}/WEB-INF/#{f}")
159
+ end
160
+ target_files += define_java_libs_task
161
+ target_files
162
+ end
163
+
164
+ def define_file_task(source, target)
165
+ if File.directory?(source)
166
+ directory target
167
+ puts %{directory "#{target}"} if verbose
168
+ else
169
+ directory File.dirname(target)
170
+ file(target => [File.dirname(target), source], &COPY_PROC)
171
+ puts %{file "#{target}" => "#{source}"} if verbose
172
+ end
173
+ target
174
+ end
175
+
176
+ def with_namespace_and_config
177
+ name, config = @name, @config
178
+ namespace name do
179
+ yield name, config
180
+ end
181
+ end
182
+
183
+ def define_copy_gems_tasks
184
+ targets = []
185
+ @config.gems.each do |gem|
186
+ define_single_gem_tasks(gem, targets)
187
+ end
188
+ targets
189
+ end
190
+
191
+ def define_single_gem_tasks(gem, targets, version = nil)
192
+ matched = Gem.source_index.search(gem, version)
193
+ fail "gem '#{gem}' not installed" if matched.empty?
194
+ spec = matched.last
195
+
196
+ gem_unpack_task_name = "gem:#{spec.name}-#{spec.version}"
197
+ return if Rake::Task.task_defined?(gem_unpack_task_name)
198
+
199
+ targets << define_file_task(spec.loaded_from,
200
+ "#{config.gem_target_path}/specifications/#{File.basename(spec.loaded_from)}")
201
+
202
+ task targets.last do
203
+ Rake::Task[gem_unpack_task_name].invoke
204
+ end
205
+
206
+ task gem_unpack_task_name => ["#{config.gem_target_path}/gems"] do |t|
207
+ Dir.chdir(t.prerequisites.last) do
208
+ ruby "-S", "gem", "unpack", "-v", spec.version.to_s, spec.name
209
+ end
210
+ end
211
+
212
+ if @config.gem_dependencies
213
+ spec.dependencies.each do |dep|
214
+ define_single_gem_tasks(dep.name, targets, dep.version_requirements)
215
+ end
216
+ end
217
+ end
218
+
219
+ def erb_binding(webxml)
220
+ binding
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,9 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ module Warbler
8
+ VERSION = "0.9"
9
+ end
data/lib/warbler.rb ADDED
@@ -0,0 +1,15 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ # Warbler is a lightweight, flexible, Rake-based system for packaging your Rails apps
8
+ # into .war files.
9
+ module Warbler
10
+ WARBLER_HOME = File.expand_path(File.dirname(__FILE__) + '/..') unless defined?(WARBLER_HOME)
11
+ end
12
+
13
+ require 'warbler/config'
14
+ require 'warbler/task'
15
+ require 'warbler/version'
@@ -0,0 +1,12 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ require 'rubygems'
8
+ require 'spec'
9
+
10
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
11
+ require 'warbler'
12
+
@@ -0,0 +1,42 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ require File.dirname(__FILE__) + '/../spec_helper'
8
+
9
+ describe Warbler::Config do
10
+ after(:each) do
11
+ rm_rf "vendor"
12
+ end
13
+
14
+ it "should have suitable default values" do
15
+ config = Warbler::Config.new
16
+ config.staging_dir.should == "tmp/war"
17
+ config.dirs.should include(*Warbler::Config::TOP_DIRS)
18
+ config.includes.should be_empty
19
+ config.java_libs.should_not be_empty
20
+ config.war_name.size.should > 0
21
+ config.webxml.should be_kind_of(OpenStruct)
22
+ config.webxml.pool.should be_kind_of(OpenStruct)
23
+ end
24
+
25
+ it "should allow configuration through an initializer block" do
26
+ config = Warbler::Config.new do |c|
27
+ c.staging_dir = "/var/tmp"
28
+ c.war_name = "mywar"
29
+ end
30
+ config.staging_dir.should == "/var/tmp"
31
+ config.war_name.should == "mywar"
32
+ end
33
+
34
+ it "should provide Rails gems by default, unless vendor/rails is present" do
35
+ config = Warbler::Config.new
36
+ config.gems.should include("rails")
37
+
38
+ mkdir_p "vendor/rails"
39
+ config = Warbler::Config.new
40
+ config.gems.should be_empty
41
+ end
42
+ end
@@ -0,0 +1,160 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ require File.dirname(__FILE__) + '/../spec_helper'
8
+
9
+ describe Warbler::Task do
10
+ before(:each) do
11
+ @rake = Rake::Application.new
12
+ Rake.application = @rake
13
+ @config = Warbler::Config.new do |config|
14
+ config.staging_dir = "pkg/tmp/war"
15
+ config.war_name = "warbler"
16
+ config.gems = ["rake"]
17
+ config.dirs = %w(bin generators lib)
18
+ config.public_html = FileList["tasks/**/*"]
19
+ config.webxml.pool.maxActive = 5
20
+ end
21
+ end
22
+
23
+ def define_tasks(*tasks)
24
+ options = tasks.last.kind_of?(Hash) ? tasks.pop : {}
25
+ @defined_tasks ||= []
26
+ tasks.each do |task|
27
+ unless @defined_tasks.include?(task)
28
+ Warbler::Task.new "warble", @config, "define_#{task}_task".to_sym do |t|
29
+ options.each {|k,v| t.send "#{k}=", v }
30
+ end
31
+ @defined_tasks << task
32
+ end
33
+ end
34
+ end
35
+
36
+ def files_should_contain(regex)
37
+ FileList["#{@config.staging_dir}/**/*"].detect {|f| f =~ regex }.should_not be_nil
38
+ end
39
+
40
+ after(:each) do
41
+ define_tasks "clean"
42
+ Rake::Task["warble:clean"].invoke
43
+ rm_rf "config"
44
+ end
45
+
46
+ it "should define a clean task for removing the staging directory" do
47
+ define_tasks "clean"
48
+ mkdir_p @config.staging_dir
49
+ Rake::Task["warble:clean"].invoke
50
+ File.exist?(@config.staging_dir).should == false
51
+ end
52
+
53
+ it "should define a public task for copying the public files" do
54
+ define_tasks "public"
55
+ Rake::Task["warble:public"].invoke
56
+ files_should_contain %r{tasks/warbler\.rake}
57
+ end
58
+
59
+ it "should define a gems task for unpacking gems" do
60
+ define_tasks "gems"
61
+ Rake::Task["warble:gems"].invoke
62
+ files_should_contain %r{WEB-INF/gems/gems/rake.*/lib/rake.rb}
63
+ files_should_contain %r{WEB-INF/gems/specifications/rake.*\.gemspec}
64
+ end
65
+
66
+ it "should define a webxml task for creating web.xml" do
67
+ define_tasks "webxml"
68
+ Rake::Task["warble:webxml"].invoke
69
+ files_should_contain %r{WEB-INF/web.xml$}
70
+ require 'rexml/document'
71
+
72
+ elements = File.open("#{@config.staging_dir}/WEB-INF/web.xml") do |f|
73
+ REXML::Document.new(f).root.elements
74
+ end
75
+ elements.to_a(
76
+ "context-param/param-name[text()='jruby.pool.maxActive']"
77
+ ).should_not be_empty
78
+ elements.to_a(
79
+ "context-param/param-name[text()='jruby.pool.maxActive']/../param-value"
80
+ ).first.text.should == "5"
81
+ end
82
+
83
+ it "should define a java_libs task for copying java libraries" do
84
+ define_tasks "java_libs"
85
+ Rake::Task["warble:java_libs"].invoke
86
+ files_should_contain %r{WEB-INF/lib/jruby-complete.*\.jar$}
87
+ end
88
+
89
+ it "should define an app task for copying application files" do
90
+ gems_ran = false
91
+ task "warble:gems" do
92
+ gems_ran = true
93
+ end
94
+ define_tasks "app"
95
+ Rake::Task["warble:app"].invoke
96
+ files_should_contain %r{WEB-INF/bin/warble$}
97
+ files_should_contain %r{WEB-INF/generators/warble/warble_generator\.rb$}
98
+ files_should_contain %r{WEB-INF/lib/warbler\.rb$}
99
+ gems_ran.should == true
100
+ end
101
+
102
+ it "should define a jar task for creating the .war" do
103
+ define_tasks "jar"
104
+ mkdir_p @config.staging_dir
105
+ touch "#{@config.staging_dir}/file.txt"
106
+ Rake::Task["warble:jar"].invoke
107
+ File.exist?("warbler.war").should == true
108
+ end
109
+
110
+ it "should define a war task for bundling up everything" do
111
+ app_ran = false; task "warble:app" do; app_ran = true; end
112
+ public_ran = false; task "warble:public" do; public_ran = true; end
113
+ jar_ran = false; task "warble:jar" do; jar_ran = true; end
114
+ webxml_ran = false; task "warble:webxml" do; webxml_ran = true; end
115
+ define_tasks "main"
116
+ Rake::Task["warble"].invoke
117
+ app_ran.should == true
118
+ public_ran.should == true
119
+ jar_ran.should == true
120
+ webxml_ran.should == true
121
+ end
122
+
123
+ it "should be able to define all tasks successfully" do
124
+ Warbler::Task.new "warble", @config
125
+ end
126
+
127
+ it "should read configuration from #{Warbler::Config::FILE}" do
128
+ mkdir_p "config"
129
+ File.open(Warbler::Config::FILE, "w") do |dest|
130
+ contents =
131
+ File.open("#{Warbler::WARBLER_HOME}/generators/warble/templates/warble.rb") do |src|
132
+ src.read
133
+ end
134
+ dest << contents.sub(/# config\.war_name/, 'config.war_name'
135
+ ).sub(/# config.gems << "tzinfo"/, 'config.gems = []')
136
+ end
137
+ t = Warbler::Task.new "warble"
138
+ t.config.war_name.should == "mywar"
139
+ end
140
+
141
+ it "should fail if a gem is requested that is not installed" do
142
+ @config.gems = ["nonexistent-gem"]
143
+ lambda {
144
+ Warbler::Task.new "warble", @config
145
+ }.should raise_error
146
+ end
147
+ end
148
+
149
+ describe "The warbler.rake file" do
150
+ it "should be able to list its contents" do
151
+ output = `#{FileUtils::RUBY} -S rake -f #{Warbler::WARBLER_HOME}/tasks/warbler.rake -T`
152
+ output.should =~ /war\s/
153
+ output.should =~ /war:app/
154
+ output.should =~ /war:clean/
155
+ output.should =~ /war:gems/
156
+ output.should =~ /war:jar/
157
+ output.should =~ /war:java_libs/
158
+ output.should =~ /war:public/
159
+ end
160
+ end
@@ -0,0 +1,22 @@
1
+ #--
2
+ # (c) Copyright 2007 Nick Sieger <nicksieger@gmail.com>
3
+ # See the file LICENSES.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ begin
8
+ # First, try w/o activating gem or touching load path
9
+ require 'warbler'
10
+ rescue LoadError
11
+ begin
12
+ # Next, try activating the gem
13
+ gem 'warbler'
14
+ require 'warbler'
15
+ rescue Gem::LoadError
16
+ # Last, add our lib dir to the load path, and try again
17
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
18
+ require 'warbler'
19
+ end
20
+ end
21
+
22
+ Warbler::Task.new
data/web.xml.erb ADDED
@@ -0,0 +1,79 @@
1
+ <!DOCTYPE web-app PUBLIC
2
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
4
+ <web-app>
5
+
6
+ <context-param>
7
+ <param-name>jruby.standalone</param-name>
8
+ <param-value><%= webxml.standalone %></param-value>
9
+ </context-param>
10
+
11
+ <% if !webxml.standalone && webxml.jruby_home %>
12
+ <!-- jruby.home can be set either here, or as the system property jruby.home -->
13
+ <context-param>
14
+ <param-name>jruby.home</param-name>
15
+ <param-value><%= webxml.jruby_home %></param-value>
16
+ </context-param>
17
+ <% end %>
18
+
19
+ <context-param>
20
+ <param-name>rails.root</param-name>
21
+ <param-value>/WEB-INF</param-value>
22
+ </context-param>
23
+
24
+ <context-param>
25
+ <param-name>rails.env</param-name>
26
+ <param-value><%= webxml.rails_env || 'production' %></param-value>
27
+ </context-param>
28
+
29
+ <% webxml.pool.marshal_dump.each do |k,v| %>
30
+ <context-param>
31
+ <param-name>jruby.pool.<%= k %></param-name>
32
+ <param-value><%= v %></param-value>
33
+ </context-param>
34
+ <% end %>
35
+
36
+ <context-param>
37
+ <param-name>files.default</param-name>
38
+ <param-value>rails</param-value>
39
+ <description>
40
+ The files servlet should forward to the rails servlet if no file could be found
41
+ </description>
42
+ </context-param>
43
+
44
+ <context-param>
45
+ <param-name>files.prefix</param-name>
46
+ <param-value></param-value>
47
+ <description>
48
+ Prefix added to static files
49
+ </description>
50
+ </context-param>
51
+
52
+ <listener>
53
+ <listener-class>org.jruby.webapp.RailsContextListener</listener-class>
54
+ </listener>
55
+
56
+ <servlet>
57
+ <servlet-name>rails</servlet-name>
58
+ <servlet-class>org.jruby.webapp.RailsServlet</servlet-class>
59
+ </servlet>
60
+ <servlet>
61
+ <servlet-name>files</servlet-name>
62
+ <servlet-class>org.jruby.webapp.FileServlet</servlet-class>
63
+ </servlet>
64
+
65
+ <!-- Allow all requests to go to the files servlet first -->
66
+ <servlet-mapping>
67
+ <servlet-name><%= webxml.servlet_name || 'files' %></servlet-name>
68
+ <url-pattern>/</url-pattern>
69
+ </servlet-mapping>
70
+
71
+ <% if webxml.jndi %>
72
+ <resource-ref>
73
+ <res-ref-name><%= webxml.jndi %></res-ref-name>
74
+ <res-type>javax.sql.DataSource</res-type>
75
+ <res-auth>Container</res-auth>
76
+ </resource-ref>
77
+ <% end %>
78
+
79
+ </web-app>
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: warbler
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.9"
7
+ date: 2007-08-30 00:00:00 -05:00
8
+ summary: Warbler chirpily constructs .war files of your Rails applications.
9
+ require_paths:
10
+ - lib
11
+ email: nick@nicksieger.com
12
+ homepage: http://caldersphere.rubyforge.org/warbler
13
+ rubyforge_project: caldersphere
14
+ description: = Warbler
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Nick Sieger
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - LICENSES.txt
36
+ - Rakefile
37
+ - web.xml.erb
38
+ - bin/warble
39
+ - generators/warble
40
+ - generators/warble/templates
41
+ - generators/warble/templates/warble.rb
42
+ - generators/warble/warble_generator.rb
43
+ - lib/activation-1.1.jar
44
+ - lib/commons-pool-1.3.jar
45
+ - lib/goldspike-1.4-SNAPSHOT.jar
46
+ - lib/jruby-complete-1.0.1.jar
47
+ - lib/warbler
48
+ - lib/warbler/config.rb
49
+ - lib/warbler/task.rb
50
+ - lib/warbler/version.rb
51
+ - lib/warbler.rb
52
+ - spec/spec_helper.rb
53
+ - spec/warbler/config_spec.rb
54
+ - spec/warbler/task_spec.rb
55
+ - tasks/warbler.rake
56
+ test_files:
57
+ - spec/warbler/config_spec.rb
58
+ - spec/warbler/task_spec.rb
59
+ rdoc_options:
60
+ - --main
61
+ - README.txt
62
+ extra_rdoc_files:
63
+ - History.txt
64
+ - Manifest.txt
65
+ - README.txt
66
+ - LICENSES.txt
67
+ executables:
68
+ - warble
69
+ extensions: []
70
+
71
+ requirements: []
72
+
73
+ dependencies: []
74
+