warbler 0.9.14 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,10 @@
1
1
  #--
2
- # (c) Copyright 2007-2009 Sun Microsystems, Inc.
3
- # See the file LICENSES.txt included with the distribution for
4
- # software license details.
2
+ # Copyright (c) 2010 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.
5
6
  #++
6
7
 
7
8
  module Warbler
8
- VERSION = "0.9.14"
9
+ VERSION = "1.0"
9
10
  end
@@ -0,0 +1,169 @@
1
+ module Warbler
2
+ class War
3
+ attr_reader :files
4
+ attr_reader :webinf_filelist
5
+
6
+ def initialize
7
+ @files = {}
8
+ end
9
+
10
+ def apply(config)
11
+ find_webinf_files(config)
12
+ find_java_libs(config)
13
+ find_java_classes(config)
14
+ find_gems_files(config)
15
+ find_public_files(config)
16
+ add_webxml(config)
17
+ add_manifest(config)
18
+ add_bundler_files(config)
19
+ end
20
+
21
+ def create(config_or_path)
22
+ war_path = config_or_path
23
+ if Warbler::Config === config_or_path
24
+ war_path = "#{config_or_path.war_name}.war"
25
+ war_path = File.join(config_or_path.autodeploy_dir, war_path) if config_or_path.autodeploy_dir
26
+ end
27
+ rm_f war_path
28
+ ensure_directory_entries
29
+ puts "Creating #{war_path}"
30
+ create_war war_path, @files
31
+ end
32
+
33
+ def add_webxml(config)
34
+ config.webinf_files.each do |wf|
35
+ if wf =~ /\.erb$/
36
+ require 'erb'
37
+ erb = ERB.new(File.open(wf) {|f| f.read })
38
+ contents = StringIO.new(erb.result(erb_binding(config.webxml)))
39
+ @files[apply_pathmaps(config, wf, :webinf)] = contents
40
+ else
41
+ @files[apply_pathmaps(config, wf, :webinf)] = wf
42
+ end
43
+ end
44
+ end
45
+
46
+ def add_manifest(config)
47
+ if config.manifest_file
48
+ @files['META-INF/MANIFEST.MF'] = config.manifest_file
49
+ else
50
+ @files['META-INF/MANIFEST.MF'] = StringIO.new(%{Manifest-Version: 1.0\nCreated-By: Warbler #{VERSION}\n\n})
51
+ end
52
+ end
53
+
54
+ def find_java_libs(config)
55
+ config.java_libs.map {|lib| add_with_pathmaps(config, lib, :java_libs) }
56
+ end
57
+
58
+ def find_java_classes(config)
59
+ config.java_classes.map {|f| add_with_pathmaps(config, f, :java_classes) }
60
+ end
61
+
62
+ def find_public_files(config)
63
+ config.public_html.map {|f| add_with_pathmaps(config, f, :public_html) }
64
+ end
65
+
66
+ def find_gems_files(config)
67
+ config.gems.each {|gem, version| find_single_gem_files(config, gem, version) }
68
+ end
69
+
70
+ def find_single_gem_files(config, gem_pattern, version = nil)
71
+ if Gem::Specification === gem_pattern
72
+ spec = gem_pattern
73
+ else
74
+ gem = case gem_pattern
75
+ when Gem::Dependency
76
+ gem_pattern
77
+ else
78
+ Gem::Dependency.new(gem_pattern, Gem::Requirement.create(version))
79
+ end
80
+
81
+ # skip development dependencies
82
+ return if gem.respond_to?(:type) and gem.type != :runtime
83
+
84
+ matched = Gem.source_index.search(gem)
85
+ fail "gem '#{gem}' not installed" if matched.empty?
86
+ spec = matched.last
87
+ end
88
+
89
+ # skip gems with no load path
90
+ return if spec.loaded_from == ""
91
+
92
+ add_with_pathmaps(config, spec.loaded_from, :gemspecs)
93
+ spec.files.each do |f|
94
+ src = File.join(spec.full_gem_path, f)
95
+ # some gemspecs may have incorrect file listings
96
+ next unless File.exist?(src)
97
+ @files[apply_pathmaps(config, File.join(spec.full_name, f), :gems)] = src
98
+ end
99
+
100
+ spec.dependencies.each {|dep| find_single_gem_files(config, dep) } if config.gem_dependencies
101
+ end
102
+
103
+ def find_webinf_files(config)
104
+ config.dirs.select do |d|
105
+ exists = File.directory?(d)
106
+ warn "warning: application directory `#{d}' does not exist or is not a directory; skipping" unless exists
107
+ exists
108
+ end.each do |d|
109
+ @files[apply_pathmaps(config, d, :application)] = nil
110
+ end
111
+ @webinf_filelist = FileList[*(config.dirs.map{|d| "#{d}/**/*"})]
112
+ @webinf_filelist.include *(config.includes.to_a)
113
+ @webinf_filelist.exclude *(config.excludes.to_a)
114
+ @webinf_filelist.map {|f| add_with_pathmaps(config, f, :application) }
115
+ end
116
+
117
+ def add_bundler_files(config)
118
+ if config.bundler
119
+ @files[apply_pathmaps(config, 'Gemfile', :application)] = 'Gemfile'
120
+ @files[apply_pathmaps(config, '.bundle/environment.rb', :application)] = '.bundle/war-environment.rb'
121
+ end
122
+ end
123
+
124
+ private
125
+ def add_with_pathmaps(config, f, map_type)
126
+ @files[apply_pathmaps(config, f, map_type)] = f
127
+ end
128
+
129
+ def erb_binding(webxml)
130
+ binding
131
+ end
132
+
133
+ def apply_pathmaps(config, file, pathmaps)
134
+ pathmaps = config.pathmaps.send(pathmaps)
135
+ pathmaps.each do |p|
136
+ file = file.pathmap(p)
137
+ end if pathmaps
138
+ file
139
+ end
140
+
141
+ def ensure_directory_entries
142
+ files.select {|k,v| !v.nil? }.each do |k,v|
143
+ dir = File.dirname(k)
144
+ while dir != "." && !files.has_key?(dir)
145
+ files[dir] = nil
146
+ dir = File.dirname(dir)
147
+ end
148
+ end
149
+ end
150
+
151
+ def create_war(war_file, entries)
152
+ Zip::ZipFile.open(war_file, Zip::ZipFile::CREATE) do |zipfile|
153
+ entries.keys.sort.each do |entry|
154
+ src = entries[entry]
155
+ if src.respond_to?(:read)
156
+ zipfile.get_output_stream(entry) {|f| f << src.read }
157
+ elsif src.nil? || File.directory?(src)
158
+ zipfile.mkdir(entry)
159
+ else
160
+ zipfile.add(entry, src)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ # Java-boosted war creation for JRuby; replaces #create_war with Java version
167
+ require 'warbler_war' if defined?(JRUBY_VERSION)
168
+ end
169
+ end
Binary file
@@ -0,0 +1,19 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ timeout: 5000
7
+
8
+ # Warning: The database defined as "test" will be erased and
9
+ # re-generated from your development database when you run "rake".
10
+ # Do not set this db to the same as development or production.
11
+ test:
12
+ adapter: sqlite3
13
+ database: db/test.sqlite3
14
+ timeout: 5000
15
+
16
+ production:
17
+ adapter: sqlite3
18
+ database: db/production.sqlite3
19
+ timeout: 5000
File without changes
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The page you were looking for doesn't exist (404)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/404.html -->
25
+ <div class="dialog">
26
+ <h1>The page you were looking for doesn't exist.</h1>
27
+ <p>You may have mistyped the address or the page may have moved.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The change you wanted was rejected (422)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/422.html -->
25
+ <div class="dialog">
26
+ <h1>The change you wanted was rejected.</h1>
27
+ <p>Maybe you tried to change something you didn't have access to.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>We're sorry, but something went wrong (500)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/500.html -->
25
+ <div class="dialog">
26
+ <h1>We're sorry, but something went wrong.</h1>
27
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
28
+ </div>
29
+ </body>
30
+ </html>
File without changes
@@ -0,0 +1,274 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
6
+ <title>Ruby on Rails: Welcome aboard</title>
7
+ <style type="text/css" media="screen">
8
+ body {
9
+ margin: 0;
10
+ margin-bottom: 25px;
11
+ padding: 0;
12
+ background-color: #f0f0f0;
13
+ font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
14
+ font-size: 13px;
15
+ color: #333;
16
+ }
17
+
18
+ h1 {
19
+ font-size: 28px;
20
+ color: #000;
21
+ }
22
+
23
+ a {color: #03c}
24
+ a:hover {
25
+ background-color: #03c;
26
+ color: white;
27
+ text-decoration: none;
28
+ }
29
+
30
+
31
+ #page {
32
+ background-color: #f0f0f0;
33
+ width: 750px;
34
+ margin: 0;
35
+ margin-left: auto;
36
+ margin-right: auto;
37
+ }
38
+
39
+ #content {
40
+ float: left;
41
+ background-color: white;
42
+ border: 3px solid #aaa;
43
+ border-top: none;
44
+ padding: 25px;
45
+ width: 500px;
46
+ }
47
+
48
+ #sidebar {
49
+ float: right;
50
+ width: 175px;
51
+ }
52
+
53
+ #footer {
54
+ clear: both;
55
+ }
56
+
57
+
58
+ #header, #about, #getting-started {
59
+ padding-left: 75px;
60
+ padding-right: 30px;
61
+ }
62
+
63
+
64
+ #header {
65
+ background-image: url("images/rails.png");
66
+ background-repeat: no-repeat;
67
+ background-position: top left;
68
+ height: 64px;
69
+ }
70
+ #header h1, #header h2 {margin: 0}
71
+ #header h2 {
72
+ color: #888;
73
+ font-weight: normal;
74
+ font-size: 16px;
75
+ }
76
+
77
+
78
+ #about h3 {
79
+ margin: 0;
80
+ margin-bottom: 10px;
81
+ font-size: 14px;
82
+ }
83
+
84
+ #about-content {
85
+ background-color: #ffd;
86
+ border: 1px solid #fc0;
87
+ margin-left: -11px;
88
+ }
89
+ #about-content table {
90
+ margin-top: 10px;
91
+ margin-bottom: 10px;
92
+ font-size: 11px;
93
+ border-collapse: collapse;
94
+ }
95
+ #about-content td {
96
+ padding: 10px;
97
+ padding-top: 3px;
98
+ padding-bottom: 3px;
99
+ }
100
+ #about-content td.name {color: #555}
101
+ #about-content td.value {color: #000}
102
+
103
+ #about-content.failure {
104
+ background-color: #fcc;
105
+ border: 1px solid #f00;
106
+ }
107
+ #about-content.failure p {
108
+ margin: 0;
109
+ padding: 10px;
110
+ }
111
+
112
+
113
+ #getting-started {
114
+ border-top: 1px solid #ccc;
115
+ margin-top: 25px;
116
+ padding-top: 15px;
117
+ }
118
+ #getting-started h1 {
119
+ margin: 0;
120
+ font-size: 20px;
121
+ }
122
+ #getting-started h2 {
123
+ margin: 0;
124
+ font-size: 14px;
125
+ font-weight: normal;
126
+ color: #333;
127
+ margin-bottom: 25px;
128
+ }
129
+ #getting-started ol {
130
+ margin-left: 0;
131
+ padding-left: 0;
132
+ }
133
+ #getting-started li {
134
+ font-size: 18px;
135
+ color: #888;
136
+ margin-bottom: 25px;
137
+ }
138
+ #getting-started li h2 {
139
+ margin: 0;
140
+ font-weight: normal;
141
+ font-size: 18px;
142
+ color: #333;
143
+ }
144
+ #getting-started li p {
145
+ color: #555;
146
+ font-size: 13px;
147
+ }
148
+
149
+
150
+ #search {
151
+ margin: 0;
152
+ padding-top: 10px;
153
+ padding-bottom: 10px;
154
+ font-size: 11px;
155
+ }
156
+ #search input {
157
+ font-size: 11px;
158
+ margin: 2px;
159
+ }
160
+ #search-text {width: 170px}
161
+
162
+
163
+ #sidebar ul {
164
+ margin-left: 0;
165
+ padding-left: 0;
166
+ }
167
+ #sidebar ul h3 {
168
+ margin-top: 25px;
169
+ font-size: 16px;
170
+ padding-bottom: 10px;
171
+ border-bottom: 1px solid #ccc;
172
+ }
173
+ #sidebar li {
174
+ list-style-type: none;
175
+ }
176
+ #sidebar ul.links li {
177
+ margin-bottom: 5px;
178
+ }
179
+
180
+ </style>
181
+ <script type="text/javascript" src="javascripts/prototype.js"></script>
182
+ <script type="text/javascript" src="javascripts/effects.js"></script>
183
+ <script type="text/javascript">
184
+ function about() {
185
+ if (Element.empty('about-content')) {
186
+ new Ajax.Updater('about-content', 'rails/info/properties', {
187
+ method: 'get',
188
+ onFailure: function() {Element.classNames('about-content').add('failure')},
189
+ onComplete: function() {new Effect.BlindDown('about-content', {duration: 0.25})}
190
+ });
191
+ } else {
192
+ new Effect[Element.visible('about-content') ?
193
+ 'BlindUp' : 'BlindDown']('about-content', {duration: 0.25});
194
+ }
195
+ }
196
+
197
+ window.onload = function() {
198
+ $('search-text').value = '';
199
+ $('search').onsubmit = function() {
200
+ $('search-text').value = 'site:rubyonrails.org ' + $F('search-text');
201
+ }
202
+ }
203
+ </script>
204
+ </head>
205
+ <body>
206
+ <div id="page">
207
+ <div id="sidebar">
208
+ <ul id="sidebar-items">
209
+ <li>
210
+ <form id="search" action="http://www.google.com/search" method="get">
211
+ <input type="hidden" name="hl" value="en" />
212
+ <input type="text" id="search-text" name="q" value="site:rubyonrails.org " />
213
+ <input type="submit" value="Search" /> the Rails site
214
+ </form>
215
+ </li>
216
+
217
+ <li>
218
+ <h3>Join the community</h3>
219
+ <ul class="links">
220
+ <li><a href="http://www.rubyonrails.org/">Ruby on Rails</a></li>
221
+ <li><a href="http://weblog.rubyonrails.org/">Official weblog</a></li>
222
+ <li><a href="http://wiki.rubyonrails.org/">Wiki</a></li>
223
+ </ul>
224
+ </li>
225
+
226
+ <li>
227
+ <h3>Browse the documentation</h3>
228
+ <ul class="links">
229
+ <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
230
+ <li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
231
+ <li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
232
+ </ul>
233
+ </li>
234
+ </ul>
235
+ </div>
236
+
237
+ <div id="content">
238
+ <div id="header">
239
+ <h1>Welcome aboard</h1>
240
+ <h2>You&rsquo;re riding Ruby on Rails!</h2>
241
+ </div>
242
+
243
+ <div id="about">
244
+ <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
245
+ <div id="about-content" style="display: none"></div>
246
+ </div>
247
+
248
+ <div id="getting-started">
249
+ <h1>Getting started</h1>
250
+ <h2>Here&rsquo;s how to get rolling:</h2>
251
+
252
+ <ol>
253
+ <li>
254
+ <h2>Use <tt>script/generate</tt> to create your models and controllers</h2>
255
+ <p>To see all available options, run it without parameters.</p>
256
+ </li>
257
+
258
+ <li>
259
+ <h2>Set up a default route and remove or rename this file</h2>
260
+ <p>Routes are set up in config/routes.rb.</p>
261
+ </li>
262
+
263
+ <li>
264
+ <h2>Create your database</h2>
265
+ <p>Run <tt>rake db:migrate</tt> to create your database. If you're not using SQLite (the default), edit <tt>config/database.yml</tt> with your username and password.</p>
266
+ </li>
267
+ </ol>
268
+ </div>
269
+ </div>
270
+
271
+ <div id="footer">&nbsp;</div>
272
+ </div>
273
+ </body>
274
+ </html>