jruby-warck 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +34 -0
- data/bin/warck +3 -0
- data/lib/jruby-warck/constants.rb +62 -0
- data/lib/jruby-warck/manipulations.rb +140 -0
- data/lib/jruby-warck/tasks/jruby.rake +45 -0
- data/lib/jruby-warck/version.rb +13 -0
- data/lib/jruby-warck.rb +40 -0
- data/lib/templates/jar-bootstrap.rb.erb +17 -0
- metadata +118 -0
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# jruby-warck
|
2
|
+
|
3
|
+
jruby-warck takes any Rack-based application and sticks it in a .war file that you can run either
|
4
|
+
|
5
|
+
* with "java -jar" or
|
6
|
+
* inside a servlet container like Tomcat, JBoss or Jetty.
|
7
|
+
|
8
|
+
Yes, it's like Warbler, but far simpler.
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
### Dependencies
|
13
|
+
* jruby-jars
|
14
|
+
* jruby-rack
|
15
|
+
|
16
|
+
### Basic
|
17
|
+
|
18
|
+
1. change directory to the root of your application
|
19
|
+
2. run "rake assets:precompile" if you've a Rails application.
|
20
|
+
3. run "warck package[war_name_here]"
|
21
|
+
3a. if you need to compile the source code, use "warck package_compiled[war_name_here]" instead
|
22
|
+
4. boom, a wild war_name_here.war appears!
|
23
|
+
5. deploy in your app server or run it in the command line
|
24
|
+
|
25
|
+
### Customizing what gets in the .war
|
26
|
+
|
27
|
+
#### Files
|
28
|
+
When packaging, jruby-warck will include all .rb files in the web archive.
|
29
|
+
|
30
|
+
Additionally, by default it will also include all .yml and .erb files, but there are two ways you can use to change this.
|
31
|
+
|
32
|
+
* To select exactly what files will be brought, create a "select.files" inside the application directory containing a glob pattern per line for the filenames you need. Note that this will override the default, so that no other files will be included.
|
33
|
+
|
34
|
+
* To keep any files from being included, create "reject.files" inside the app directory containing a glob pattern per line for the filenames you want to reject.
|
data/bin/warck
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'jruby-rack'
|
3
|
+
|
4
|
+
module JrubyWarck
|
5
|
+
module Constants
|
6
|
+
HOME = File.expand_path(File.dirname(__FILE__) + '/../..') unless defined?(HOME)
|
7
|
+
|
8
|
+
WEB_XML = <<-XML
|
9
|
+
<!DOCTYPE web-app PUBLIC
|
10
|
+
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
11
|
+
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
12
|
+
<web-app>
|
13
|
+
<filter>
|
14
|
+
<filter-name>RackFilter</filter-name>
|
15
|
+
<filter-class>org.jruby.rack.RackFilter</filter-class>
|
16
|
+
</filter>
|
17
|
+
<filter-mapping>
|
18
|
+
<filter-name>RackFilter</filter-name>
|
19
|
+
<url-pattern>/*</url-pattern>
|
20
|
+
</filter-mapping>
|
21
|
+
|
22
|
+
<listener>
|
23
|
+
<listener-class><%= context_listener %></listener-class>
|
24
|
+
</listener>
|
25
|
+
</web-app>
|
26
|
+
XML
|
27
|
+
|
28
|
+
CONTEXT_LISTENERS = {
|
29
|
+
:rack => "org.jruby.rack.RackServletContextListener",
|
30
|
+
:rails => "org.jruby.rack.rails.RailsServletContextListener"
|
31
|
+
}
|
32
|
+
|
33
|
+
MANIFEST_MF = <<-MANIFEST
|
34
|
+
Manifest-Version: 1.0
|
35
|
+
Created-By: jruby-warck
|
36
|
+
Main-Class: org.jruby.JarBootstrapMain
|
37
|
+
Class-Path: /opt/jruby/lib/jruby-complete/jruby-complete.jar #{::JRubyJars.jruby_rack_jar_path}
|
38
|
+
MANIFEST
|
39
|
+
|
40
|
+
INIT = <<-_INIT
|
41
|
+
# rack.version: #{JRuby::Rack::VERSION}
|
42
|
+
_INIT
|
43
|
+
|
44
|
+
RUNNING_FROM = Dir.pwd
|
45
|
+
|
46
|
+
BUILD_DIR = "/tmp/war-#{Time.now.to_i}"
|
47
|
+
WEB_INF = BUILD_DIR + "/WEB-INF"
|
48
|
+
META_INF = BUILD_DIR + "/META-INF"
|
49
|
+
|
50
|
+
RACKUP_FILE = "config.ru"
|
51
|
+
|
52
|
+
BOOTSTRAP_ERB = File.read(File.exist?(custom_bootstrap = RUNNING_FROM + "/jar-bootstrap.rb.erb") ? custom
|
53
|
+
: (HOME + "/lib/templates/jar-bootstrap.rb.erb"))
|
54
|
+
|
55
|
+
# additional filename patterns to be included inside the archive
|
56
|
+
# default is all yml files
|
57
|
+
SELECT_FILES = FileList[IO.readlines(Dir.pwd + "/select.files").map(&:chomp).reject { |line| line[0] == "#" }] rescue FileList["**/*.yml", "**/*.erb"]
|
58
|
+
# filename patterns to be rejected from the archive
|
59
|
+
# default is none
|
60
|
+
REJECT_FILES = FileList[IO.readlines(Dir.pwd + "/reject.files").map(&:chomp).reject { |line| line[0] == "#" }] rescue FileList[]
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'erb'
|
3
|
+
require 'jruby-warck/constants'
|
4
|
+
|
5
|
+
module JrubyWarck::Manipulations
|
6
|
+
include JrubyWarck::Constants
|
7
|
+
|
8
|
+
def create_archive_dirs
|
9
|
+
puts "++ Creating archive directories"
|
10
|
+
mkdir_p "#{BUILD_DIR}/assets" if Rake::Task.task_defined?("assets:precompile")
|
11
|
+
mkdir_p WEB_INF
|
12
|
+
mkdir_p META_INF
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_manifest_file
|
16
|
+
puts "++ Adding MANIFEST to #{META_INF}"
|
17
|
+
manifest = File.new(META_INF + "/MANIFEST.MF", "w")
|
18
|
+
manifest.puts(MANIFEST_MF)
|
19
|
+
manifest.close
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_deployment_descriptor(path, framework = :rack)
|
23
|
+
puts "++ Generating web.xml"
|
24
|
+
context_listener = CONTEXT_LISTENERS[framework.to_sym]
|
25
|
+
|
26
|
+
web_xml = File.new(path, "w")
|
27
|
+
web_xml.puts(ERB.new(WEB_XML).result(binding))
|
28
|
+
web_xml.close
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_deployment_descriptor(framework = :rack)
|
32
|
+
web_xml_path = "web.xml"
|
33
|
+
|
34
|
+
# if there is no web.xml file, generate it
|
35
|
+
generate_deployment_descriptor(web_xml_path, framework) if !File.exist?(web_xml_path)
|
36
|
+
|
37
|
+
puts "++ Adding web.xml to #{WEB_INF}"
|
38
|
+
cp web_xml_path, "#{WEB_INF}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_init_file
|
42
|
+
puts "++ Generating init.rb"
|
43
|
+
|
44
|
+
init = File.new(META_INF + "/init.rb", "w")
|
45
|
+
init.puts(INIT)
|
46
|
+
init.close
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_rackup_file
|
50
|
+
puts "++ Copying #{RACKUP_FILE} to #{WEB_INF}"
|
51
|
+
cp RACKUP_FILE, WEB_INF
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_ruby_files
|
55
|
+
@ruby_files = FileList["**/*.rb"]
|
56
|
+
puts "++ Copying #{@ruby_files.size} Ruby sources to #{WEB_INF}"
|
57
|
+
|
58
|
+
@ruby_files.each do |file|
|
59
|
+
mkdir_p file.pathmap(WEB_INF + "/%d") unless File.exists? file.pathmap(WEB_INF + "/%d")
|
60
|
+
cp file, (WEB_INF + "/" + file)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_class_files
|
65
|
+
puts "++ Moving .class files to #{WEB_INF}"
|
66
|
+
puts "++ Generating .rb stubs in #{WEB_INF}"
|
67
|
+
|
68
|
+
@class_files.each do |file|
|
69
|
+
mkdir_p file.pathmap(WEB_INF + "/%d") unless File.exists? file.pathmap(WEB_INF + "/%d")
|
70
|
+
mv file, (WEB_INF + "/" + file)
|
71
|
+
|
72
|
+
stub = File.open((WEB_INF + "/" + file).sub(/\.class$/, ".rb"), "w")
|
73
|
+
stub.puts("load __FILE__.sub(/\.rb$/, '.class')")
|
74
|
+
stub.close
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_public_files
|
79
|
+
puts "++ Copying public files to #{BUILD_DIR}"
|
80
|
+
|
81
|
+
(FileList["public/**/*"] - FileList[REJECT_FILES]).each do |file|
|
82
|
+
if File.directory?(file)
|
83
|
+
puts " ++ Creating #{file.pathmap("%{public,#{BUILD_DIR}}d/%f")
|
84
|
+
}"
|
85
|
+
mkdir_p file.pathmap("%{public,#{BUILD_DIR}}d/%f")
|
86
|
+
else
|
87
|
+
puts " ++ Copying #{file.pathmap("%{public,#{BUILD_DIR}}d/%f")
|
88
|
+
}"
|
89
|
+
cp file, file.pathmap("%{public,#{BUILD_DIR}}d/%f")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def add_additional_files
|
95
|
+
puts "++ Copying additional files to #{WEB_INF}"
|
96
|
+
FileList[SELECT_FILES].each do |file|
|
97
|
+
mkdir_p file.pathmap("#{WEB_INF}/%d") unless File.exists?(file.pathmap("#{WEB_INF}/%d"))
|
98
|
+
cp file, file.pathmap("#{WEB_INF}/%d/%f")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def add_bootstrap_script(archive_name)
|
103
|
+
puts "++ Creating bootstrapping script"
|
104
|
+
bootstrap = File.new("#{BUILD_DIR}/jar-bootstrap.rb", "w")
|
105
|
+
# archive_name gets passed in the binding
|
106
|
+
bootstrap.puts(ERB.new(BOOTSTRAP_ERB).result(binding))
|
107
|
+
bootstrap.close
|
108
|
+
end
|
109
|
+
|
110
|
+
def archive_war(archive_name)
|
111
|
+
puts "++ Creating war file #{archive_name}.war"
|
112
|
+
|
113
|
+
if File.exist? "#{archive_name}.war"
|
114
|
+
$stderr.puts "!! #{archive_name}.war already exists, aborting"
|
115
|
+
exit 1
|
116
|
+
end
|
117
|
+
|
118
|
+
Zip::ZipFile.open("#{RUNNING_FROM}/#{archive_name}.war", Zip::ZipFile::CREATE) do |zip|
|
119
|
+
Dir.chdir(BUILD_DIR)
|
120
|
+
Dir["**/"].each { |d| zip.mkdir(d, 0744) }
|
121
|
+
FileList["**/*"].exclude { |f| File.directory?(f) }.each { |f| puts " ++ Adding #{f}"; zip.add(f, f) }
|
122
|
+
|
123
|
+
zip.close
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def compile_ruby_scripts
|
128
|
+
@ruby_files = FileList["**/*.rb"]
|
129
|
+
|
130
|
+
`jrubyc #{@ruby_files.join(" ")}`
|
131
|
+
|
132
|
+
@class_files = FileList["**/*.class"] - FileList["tmp/**/*"]
|
133
|
+
|
134
|
+
unless @ruby_files.size.eql?(@class_files.size)
|
135
|
+
puts "** Warning: it seems that some ruby files were not compiled"
|
136
|
+
puts ".rb files: #{@ruby_files.size}"
|
137
|
+
puts ".class files: #{@class_files.size}"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'jruby-warck/manipulations'
|
2
|
+
require 'jruby-warck/constants'
|
3
|
+
|
4
|
+
include JrubyWarck::Manipulations
|
5
|
+
include JrubyWarck::Constants
|
6
|
+
|
7
|
+
desc "Create a .war package out of this application"
|
8
|
+
task :package, [:archive_name, :framework] do |t, args|
|
9
|
+
args.with_defaults(:archive_name => File.basename(RUNNING_FROM), :framework => :rack)
|
10
|
+
|
11
|
+
create_archive_dirs
|
12
|
+
add_manifest_file
|
13
|
+
add_deployment_descriptor(args[:framework])
|
14
|
+
add_rackup_file if File.exists?(RACKUP_FILE)
|
15
|
+
add_init_file
|
16
|
+
add_ruby_files
|
17
|
+
add_public_files
|
18
|
+
add_additional_files
|
19
|
+
add_bootstrap_script(args[:archive_name])
|
20
|
+
archive_war(args[:archive_name])
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Create a .war package out of this application, compiling Ruby sources to .class files"
|
24
|
+
task :package_compiled, [:archive_name, :framework] do |t, args|
|
25
|
+
args.with_defaults(:archive_name => File.basename(RUNNING_FROM), :framework => :rack)
|
26
|
+
|
27
|
+
create_archive_dirs
|
28
|
+
add_manifest_file
|
29
|
+
add_deployment_descriptor(args[:framework])
|
30
|
+
add_rackup_file if File.exists?(RACKUP_FILE)
|
31
|
+
add_init_file
|
32
|
+
compile_ruby_scripts
|
33
|
+
add_class_files
|
34
|
+
add_public_files
|
35
|
+
add_additional_files
|
36
|
+
add_bootstrap_script(args[:archive_name])
|
37
|
+
archive_war(args[:archive_name])
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Generate a deployment descriptor (web.xml) to be customized for this application"
|
41
|
+
task :webxml, :framework do |t, args|
|
42
|
+
args.with_defaults(:framework => :rack)
|
43
|
+
|
44
|
+
generate_deployment_descriptor("web.xml", args[:framework])
|
45
|
+
end
|
data/lib/jruby-warck.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'jruby-warck/version'
|
3
|
+
require 'jruby-warck/constants'
|
4
|
+
require 'jruby-warck/manipulations'
|
5
|
+
|
6
|
+
require 'zip/zip'
|
7
|
+
require 'erb'
|
8
|
+
|
9
|
+
class JrubyWarck::Application < Rake::Application
|
10
|
+
include JrubyWarck::Constants
|
11
|
+
include JrubyWarck::Manipulations
|
12
|
+
include Rake::DSL
|
13
|
+
|
14
|
+
def name
|
15
|
+
'warck'
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_rakefile
|
23
|
+
Rake::TaskManager.record_task_metadata = true
|
24
|
+
task :default do
|
25
|
+
options.show_tasks = :tasks
|
26
|
+
options.show_task_pattern = //
|
27
|
+
puts "#{name} #{JrubyWarck::VERSION.version} -- package your Rack application in a .war file that can be run from the command line or in a servlet container!"
|
28
|
+
puts "Available commands:"
|
29
|
+
display_tasks_and_comments
|
30
|
+
end
|
31
|
+
|
32
|
+
load 'jruby-warck/tasks/jruby.rake'
|
33
|
+
end
|
34
|
+
|
35
|
+
def run
|
36
|
+
Rake.application = self
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'zip/zip'
|
3
|
+
|
4
|
+
unless File.exist?("<%= archive_name %>.war.extracted")
|
5
|
+
puts "First run... extracting war contents to <%= archive_name %>.war.extracted..."
|
6
|
+
%x{unzip <%= archive_name %>.war -d<%= archive_name %>.war.extracted}
|
7
|
+
puts "Done."
|
8
|
+
end
|
9
|
+
|
10
|
+
puts "Loading Puma..."
|
11
|
+
|
12
|
+
Dir.chdir("<%= archive_name %>.war.extracted/WEB-INF")
|
13
|
+
|
14
|
+
NOT_IN_SERVLET_CONTAINER = true
|
15
|
+
|
16
|
+
gem 'puma'
|
17
|
+
load Gem.bin_path('puma', 'puma')
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jruby-warck
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nuno Correia
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rubyzip
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: jruby-jars
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jruby-rack
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Kinda like warbler, except WAR-only and contained in a single Rakefile.
|
79
|
+
email:
|
80
|
+
- nuno-g-correia@ext.ptinovacao.pt
|
81
|
+
executables:
|
82
|
+
- warck
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- bin/warck
|
87
|
+
- lib/templates/jar-bootstrap.rb.erb
|
88
|
+
- lib/jruby-warck/tasks/jruby.rake
|
89
|
+
- lib/jruby-warck/manipulations.rb
|
90
|
+
- lib/jruby-warck/constants.rb
|
91
|
+
- lib/jruby-warck/version.rb
|
92
|
+
- lib/jruby-warck.rb
|
93
|
+
- README.md
|
94
|
+
homepage: http://github.com/ptinovacao/rubygem-jruby-warck
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.23
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Kinda like warbler, except our way
|
118
|
+
test_files: []
|