From 78f9d71bfdd7471d1fa430d53d4cf6e15b1a254e Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Wed, 20 Feb 2013 16:22:09 -0600 Subject: [PATCH 1/8] Add warbler to JRuby gems --- Gemfile | 1 + Gemfile.lock | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/Gemfile b/Gemfile index 66653d80..20756d67 100644 --- a/Gemfile +++ b/Gemfile @@ -67,6 +67,7 @@ group :development do gem 'yard', require: nil gem 'redcarpet', require: nil, platform: :mri gem 'fdoc' + gem 'warbler', git: 'git://github.com/jruby/warbler.git', platform: :jruby end diff --git a/Gemfile.lock b/Gemfile.lock index 4559daf7..c4ca8c9f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,16 @@ GIT specs: git (1.2.5) +GIT + remote: git://github.com/jruby/warbler.git + revision: ce3ce4df137504822e4cbb9399dee7e7dd767c44 + specs: + warbler (1.3.7.dev) + jruby-jars (>= 1.5.6) + jruby-rack (>= 1.0.0) + rake (>= 0.9.6) + rubyzip (>= 0.9.8) + GIT remote: git://github.com/rails/rails.git revision: f1efecfc3f009d7b25a0b72170914a2739cb3765 @@ -124,6 +134,8 @@ GEM jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) + jruby-jars (1.7.2) + jruby-rack (1.1.13.1) json (1.7.7) json (1.7.7-java) json-schema (1.1.1) @@ -176,6 +188,7 @@ GEM rspec-core (~> 2.12.0) rspec-expectations (~> 2.12.0) rspec-mocks (~> 2.12.0) + rubyzip (0.9.9) sass (3.2.5) sass-rails (3.2.6) railties (~> 3.2.0) @@ -283,4 +296,5 @@ DEPENDENCIES url_validation user-agent validates_timeliness + warbler! yard From 70c8f374e06902183e0fbffa531e12f340692bba Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Thu, 21 Feb 2013 14:35:11 -0600 Subject: [PATCH 2/8] JRuby war building support --- .gitignore | 3 + Gemfile | 7 +- config/warble.rb | 151 +++++++++++++++++++++++++++++++++ lib/tasks/warbler/warbler.rake | 8 ++ 4 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 config/warble.rb create mode 100644 lib/tasks/warbler/warbler.rake diff --git a/.gitignore b/.gitignore index 445beaab..4aa8bccf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ node_modules doc/fdoc-html tmp/cache/* +*.war +public/assets +bin/* diff --git a/Gemfile b/Gemfile index 20756d67..a8cd7b22 100644 --- a/Gemfile +++ b/Gemfile @@ -67,7 +67,6 @@ group :development do gem 'yard', require: nil gem 'redcarpet', require: nil, platform: :mri gem 'fdoc' - gem 'warbler', git: 'git://github.com/jruby/warbler.git', platform: :jruby end @@ -79,3 +78,9 @@ group :test do end gem 'sql_origin', groups: [:development, :test] + +# Warbler seems to bundle its own gemspec even when skipping +# :development. The gemspec requires warbler/version which doesn't +# exist so the whole thing blows up. Putting this in :default group +# until I can figure out how to fix it. +gem 'warbler', git: 'git://github.com/jruby/warbler.git', platform: :jruby, require: nil diff --git a/config/warble.rb b/config/warble.rb new file mode 100644 index 00000000..5a94dd97 --- /dev/null +++ b/config/warble.rb @@ -0,0 +1,151 @@ +# Disable Rake-environment-task framework detection by uncommenting/setting to false +Warbler.framework_detection = false + +# Warbler web application assembly configuration file +Warbler::Config.new do |config| + # Features: additional options controlling how the jar is built. + # Currently the following features are supported: + # - gemjar: package the gem repository in a jar file in WEB-INF/lib + # - executable: embed a web server and make the war executable + # - compiled: compile .rb files to .class files + config.features = %w(executable runnable) + + # Application directories to be included in the webapp. + config.dirs = %w(app bin config data db lib log vendor tmp) + + # Additional files/directories to include, above those in config.dirs + # config.includes = FileList["db"] + + # Additional files/directories to exclude + config.excludes = FileList["spec", "test", "tmp/**/*", "log/*"] + + # Additional Java .jar files to include. Note that if .jar files are placed + # in lib (and not otherwise excluded) then they need not be mentioned here. + # JRuby and JRuby-Rack are pre-loaded in this list. Be sure to include your + # own versions if you directly set the value + # config.java_libs += FileList["lib/java/*.jar"] + + # Loose Java classes and miscellaneous files to be included. + # config.java_classes = FileList["target/classes/**.*"] + + # One or more pathmaps defining how the java classes should be copied into + # the archive. The example pathmap below accompanies the java_classes + # configuration above. See http://rake.rubyforge.org/classes/String.html#M000017 + # for details of how to specify a pathmap. + # config.pathmaps.java_classes << "%{target/classes/,}p" + + # Bundler support is built-in. If Warbler finds a Gemfile in the + # project directory, it will be used to collect the gems to bundle + # in your application. If you wish to explicitly disable this + # functionality, uncomment here. + # config.bundler = false + + # An array of Bundler groups to avoid including in the war file. + # Defaults to ["development", "test", "assets"]. + # config.bundle_without = [] + + # Other gems to be included. If you don't use Bundler or a gemspec + # file, you need to tell Warbler which gems your application needs + # so that they can be packaged in the archive. + # For Rails applications, the Rails gems are included by default + # unless the vendor/rails directory is present. + # config.gems += ["activerecord-jdbcmysql-adapter", "jruby-openssl"] + # config.gems << "tzinfo" + + # Uncomment this if you don't want to package rails gem. + # config.gems -= ["rails"] + + # The most recent versions of gems are used. + # You can specify versions of gems by using a hash assignment: + # config.gems["rails"] = "2.3.10" + + # You can also use regexps or Gem::Dependency objects for flexibility or + # finer-grained control. + # config.gems << /^merb-/ + # config.gems << Gem::Dependency.new("merb-core", "= 0.9.3") + + # Include gem dependencies not mentioned specifically. Default is + # true, uncomment to turn off. + # config.gem_dependencies = false + + # Array of regular expressions matching relative paths in gems to be + # excluded from the war. Defaults to empty, but you can set it like + # below, which excludes test files. + config.gem_excludes = [/^(test|spec)\//] + + # Pathmaps for controlling how application files are copied into the archive + # config.pathmaps.application = ["WEB-INF/%p"] + + # Name of the archive (without the extension). Defaults to the basename + # of the project directory. + config.jar_name = "squash" + + # Name of the MANIFEST.MF template for the war file. Defaults to a simple + # MANIFEST.MF that contains the version of Warbler used to create the war file. + # config.manifest_file = "config/MANIFEST.MF" + + # When using the 'compiled' feature and specified, only these Ruby + # files will be compiled. Default is to compile all \.rb files in + # the application. + # config.compiled_ruby_files = FileList['app/**/*.rb'] + + # === War files only below here === + + # Path to the pre-bundled gem directory inside the war file. Default + # is 'WEB-INF/gems'. Specify path if gems are already bundled + # before running Warbler. This also sets 'gem.path' inside web.xml. + # config.gem_path = "WEB-INF/vendor/bundler_gems" + + # Files for WEB-INF directory (next to web.xml). This contains + # web.xml by default. If there is an .erb-File it will be processed + # with webxml-config. You may want to exclude this file via + # config.excludes. + # config.webinf_files += FileList["jboss-web.xml"] + + # Files to be included in the root of the webapp. Note that files in public + # will have the leading 'public/' part of the path stripped during staging. + # config.public_html = FileList["public/**/*", "doc/**/*"] + + # Pathmaps for controlling how public HTML files are copied into the .war + # config.pathmaps.public_html = ["%{public/,}p"] + + # Embedded webserver to use with the 'executable' feature. Currently supported + # webservers are: + # * winstone (default) - Winstone 0.9.10 from sourceforge + # * jenkins-ci.winstone - Improved Winstone from Jenkins CI + # * jetty - Embedded Jetty from Eclipse + config.webserver = 'jetty' + + # Value of RAILS_ENV for the webapp -- default as shown below + config.webxml.rails.env = 'production' + + # Application booter to use, one of :rack, :rails, or :merb (autodetected by default) + config.webxml.booter = :rails + + # Set JRuby to run in 1.9 mode. + config.webxml.jruby.compat.version = "1.9" + + # When using the :rack booter, "Rackup" script to use. + # - For 'rackup.path', the value points to the location of the rackup + # script in the web archive file. You need to make sure this file + # gets included in the war, possibly by adding it to config.includes + # or config.webinf_files above. + # - For 'rackup', the rackup script you provide as an inline string + # is simply embedded in web.xml. + # The script is evaluated in a Rack::Builder to load the application. + # Examples: + # config.webxml.rackup.path = 'WEB-INF/hello.ru' + # config.webxml.rackup = %{require './lib/demo'; run Rack::Adapter::Camping.new(Demo)} + # config.webxml.rackup = require 'cgi' && CGI::escapeHTML(File.read("config.ru")) + + # Control the pool of Rails runtimes. Leaving unspecified means + # the pool will grow as needed to service requests. It is recommended + # that you fix these values when running a production server! + # If you're using threadsafe! mode, you probably don't want to set these values, + # since 1 runtime(default for threadsafe mode) will be enough. + config.webxml.jruby.min.runtimes = 1 + config.webxml.jruby.max.runtimes = 1 + + # JNDI data source name + # config.webxml.jndi = 'jdbc/rails' +end diff --git a/lib/tasks/warbler/warbler.rake b/lib/tasks/warbler/warbler.rake new file mode 100644 index 00000000..a2df2aab --- /dev/null +++ b/lib/tasks/warbler/warbler.rake @@ -0,0 +1,8 @@ +if RUBY_PLATFORM == "java" + desc "Build a WAR file of project using Warbler" + task :war => "assets:precompile:all" do + require 'warbler' + Warbler::Task.new(:warble) + Rake::Task["warble"].invoke + end +end From f7efd34438660a35aeb13e0fb3ae3a4ac73bc5cb Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Tue, 12 Mar 2013 10:55:28 -0500 Subject: [PATCH 3/8] Add script directory to warbler bundle Thanks to jruby/warbler#141, this will allow us to do the following in order to start a console, run a rake task, etc. directly from the WAR file: java -jar squash.war -S script/rails console --- config/warble.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/warble.rb b/config/warble.rb index 5a94dd97..77c36405 100644 --- a/config/warble.rb +++ b/config/warble.rb @@ -11,7 +11,7 @@ config.features = %w(executable runnable) # Application directories to be included in the webapp. - config.dirs = %w(app bin config data db lib log vendor tmp) + config.dirs = %w(app bin config data db lib log script vendor tmp) # Additional files/directories to include, above those in config.dirs # config.includes = FileList["db"] From 5a6d873edf6abd1ec7de0edbb0e83c0680673488 Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Tue, 12 Mar 2013 10:59:39 -0500 Subject: [PATCH 4/8] Use my fork of warbler until jruby/warbler#141 is merged --- Gemfile | 2 +- Gemfile.lock | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index a8cd7b22..1727fd29 100644 --- a/Gemfile +++ b/Gemfile @@ -83,4 +83,4 @@ gem 'sql_origin', groups: [:development, :test] # :development. The gemspec requires warbler/version which doesn't # exist so the whole thing blows up. Putting this in :default group # until I can figure out how to fix it. -gem 'warbler', git: 'git://github.com/jruby/warbler.git', platform: :jruby, require: nil +gem 'warbler', github: 'bjeanes/warbler', platform: :jruby, require: nil diff --git a/Gemfile.lock b/Gemfile.lock index c4ca8c9f..5085be9f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,16 +19,6 @@ GIT specs: git (1.2.5) -GIT - remote: git://github.com/jruby/warbler.git - revision: ce3ce4df137504822e4cbb9399dee7e7dd767c44 - specs: - warbler (1.3.7.dev) - jruby-jars (>= 1.5.6) - jruby-rack (>= 1.0.0) - rake (>= 0.9.6) - rubyzip (>= 0.9.8) - GIT remote: git://github.com/rails/rails.git revision: f1efecfc3f009d7b25a0b72170914a2739cb3765 @@ -77,6 +67,15 @@ GIT rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) +PATH + remote: /Users/bjeanes/Code/warbler + specs: + warbler (1.3.7.dev) + jruby-jars (>= 1.5.6) + jruby-rack (>= 1.0.0) + rake (>= 0.9.6) + rubyzip (>= 0.9.8) + GEM remote: https://rubygems.org/ specs: @@ -134,7 +133,7 @@ GEM jquery-rails (2.2.1) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - jruby-jars (1.7.2) + jruby-jars (1.7.3) jruby-rack (1.1.13.1) json (1.7.7) json (1.7.7-java) From 65b6de2b076bc1bc929fe43fe24bfda635b57391 Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Tue, 12 Mar 2013 14:12:07 -0500 Subject: [PATCH 5/8] Make session secret configurable through Configoro --- config/environments/common/application.yml | 2 ++ config/initializers/secret_token.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 config/environments/common/application.yml diff --git a/config/environments/common/application.yml b/config/environments/common/application.yml new file mode 100644 index 00000000..4faaf8f6 --- /dev/null +++ b/config/environments/common/application.yml @@ -0,0 +1,2 @@ +# Replace this with a random value (e.g. result of `head -c2048 /dev/urandom | openssl sha1`) +secret_token: \ No newline at end of file diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 10a4401e..6c76bfb2 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -18,4 +18,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -Squash::Application.config.secret_token = '_SECRET_' +Squash::Application.config.secret_token = Squash::Configuration.application.secret_token || '_SECRET_' From 160d1af661d7c6ae6ca12ed6c662ab305bcc30ff Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Tue, 12 Mar 2013 14:15:51 -0500 Subject: [PATCH 6/8] Add Gemfile.lock accidentally excluded from earlier commit --- Gemfile.lock | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5085be9f..85ba3b3d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,16 @@ GIT specs: git (1.2.5) +GIT + remote: git://github.com/bjeanes/warbler.git + revision: 3363641ec52c78ab74d990f287536a78b1ea0eda + specs: + warbler (1.3.7.dev) + jruby-jars (>= 1.5.6) + jruby-rack (>= 1.0.0) + rake (>= 0.9.6) + rubyzip (>= 0.9.8) + GIT remote: git://github.com/rails/rails.git revision: f1efecfc3f009d7b25a0b72170914a2739cb3765 @@ -67,15 +77,6 @@ GIT rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) -PATH - remote: /Users/bjeanes/Code/warbler - specs: - warbler (1.3.7.dev) - jruby-jars (>= 1.5.6) - jruby-rack (>= 1.0.0) - rake (>= 0.9.6) - rubyzip (>= 0.9.8) - GEM remote: https://rubygems.org/ specs: From 07d58df543b10cd90dc93584dc372cb487135221 Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Tue, 12 Mar 2013 14:23:56 -0500 Subject: [PATCH 7/8] Ignore database.yml and provide an example instead `setup.rb` can still be used to generate a working database.yml but local changes to this file won't result in a dirty directory --- .gitignore | 1 + config/{database.yml => database.example.yml} | 0 2 files changed, 1 insertion(+) rename config/{database.yml => database.example.yml} (100%) diff --git a/.gitignore b/.gitignore index 4aa8bccf..9740804b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ tmp/cache/* *.war public/assets bin/* +config/database.yml diff --git a/config/database.yml b/config/database.example.yml similarity index 100% rename from config/database.yml rename to config/database.example.yml From 5f3c487723eab3a3e2670cb7d2b0791f8c7bad2e Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Wed, 13 Mar 2013 11:52:44 -0500 Subject: [PATCH 8/8] Allow for an out-of-repo directory of config files --- config/initializers/extra_config_directory.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 config/initializers/extra_config_directory.rb diff --git a/config/initializers/extra_config_directory.rb b/config/initializers/extra_config_directory.rb new file mode 100644 index 00000000..0b5e0771 --- /dev/null +++ b/config/initializers/extra_config_directory.rb @@ -0,0 +1,7 @@ +config_dir = ENV['CONFIG_DIR'] + +if config_dir && File.directory?(config_dir) + Dir["#{config_dir}/**/*.yml"].sort.each do |config| + Squash::Configuration << config + end +end