backlog 0.34.1 → 0.34.2

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.
@@ -1,160 +0,0 @@
1
- require 'war_config'
2
- require 'fileutils'
3
-
4
- module War
5
- class Runner
6
-
7
- attr_accessor :config
8
- attr_accessor :jetty_main
9
- attr_accessor :jetty_tmp
10
- attr_accessor :jetty_config
11
- attr_accessor :war_override
12
- attr_accessor :classpath
13
-
14
- def initialize(config = Configuration.instance)
15
- @config = config
16
- @jetty_main = 'org.mortbay.start.Main'
17
- @jetty_tmp = File.join('tmp', 'jetty')
18
- @jetty_config = File.join(jetty_tmp, 'jetty.xml')
19
- @war_override = File.join(jetty_tmp, 'war-override.xml')
20
- end
21
-
22
- def run_standalone
23
- @config.standalone = true
24
- run
25
- end
26
-
27
- def run
28
- add_jetty_libraries
29
- add_jetty_config
30
- add_war_override
31
- classpath_string = classpath.join(config.os_path_separator)
32
- java_opts = config.jetty_java_opts.dup
33
- java_opts << ' -Xmx128m' unless java_opts =~ /-Xmx/
34
- java_opts << " -Djetty.port=#{config.jetty_port}" unless java_opts =~ /jetty.port/
35
- cmd = "java #{java_opts} -cp \"#{classpath_string}\" #{jetty_main} #{jetty_config}"
36
- puts cmd
37
- system(cmd)
38
- end
39
-
40
- def add_war_override
41
- # always create a new override file, regardless of whether one exists
42
- File.open(war_override, 'w') { |out| out << create_war_override }
43
- end
44
-
45
- def create_war_override
46
- require 'erb'
47
- template = <<END_OF_WEB_INF_OVERRIDE
48
- <web-app>
49
-
50
- <context-param>
51
- <param-name>rails.env</param-name>
52
- <param-value><%= config.rails_env_embedded %></param-value>
53
- </context-param>
54
-
55
- </web-app>
56
- END_OF_WEB_INF_OVERRIDE
57
-
58
- erb = ERB.new(template)
59
- erb.result(binding)
60
-
61
- end
62
-
63
- def add_jetty_libraries
64
- # Get the Jetty libraries
65
- @classpath = []
66
- FileUtils.makedirs(jetty_tmp)
67
- for lib in config.jetty_libraries.values
68
- target = File.join(jetty_tmp, lib.file)
69
- unless File.exists?(target)
70
- puts "Downloading #{lib.file}..."
71
- lib.install(config, target)
72
- end
73
- @classpath << target
74
- end
75
- end
76
-
77
- def add_jetty_config
78
- # Create the configuration
79
- jetty_user_config = File.join('config', 'jetty.xml')
80
- jetty_config_data = File.read(jetty_user_config) if File.exists?(jetty_user_config)
81
- jetty_config_data ||= create_jetty_config
82
- File.open(jetty_config, 'w') { |out| out << jetty_config_data }
83
- end
84
-
85
- def create_jetty_config
86
- require 'erb'
87
- template = <<END_OF_JETTY_XML
88
- <?xml version="1.0"?>
89
- <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
90
- <Configure id="Server" class="org.mortbay.jetty.Server">
91
-
92
- <Set name="ThreadPool">
93
- <New class="org.mortbay.thread.BoundedThreadPool">
94
- <Set name="minThreads">10</Set>
95
- <Set name="lowThreads">50</Set>
96
- <Set name="maxThreads">250</Set>
97
- </New>
98
- </Set>
99
-
100
- <Call name="addConnector">
101
- <Arg>
102
- <New class="org.mortbay.jetty.nio.SelectChannelConnector">
103
- <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
104
- <Set name="maxIdleTime">30000</Set>
105
- <Set name="Acceptors">2</Set>
106
- <Set name="confidentialPort">8443</Set>
107
- </New>
108
- </Arg>
109
- </Call>
110
-
111
- <Set name="handlers">
112
- <Array type="org.mortbay.jetty.Handler">
113
- <Item>
114
- <New class="org.mortbay.jetty.webapp.WebAppContext">
115
- <Arg><%= config.staging %></Arg>
116
- <Arg>/<%= config.name %></Arg>
117
- <Set name="ConfigurationClasses">
118
- <Array id="plusConfig" type="java.lang.String">
119
- <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
120
- <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
121
- <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
122
- <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
123
- <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
124
- </Array>
125
- </Set>
126
- <Set name="overrideDescriptor"><%= war_override %></Set>
127
- </New>
128
- </Item>
129
- <Item>
130
- <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
131
- </Item>
132
- <Item>
133
- <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>
134
- </Item>
135
- </Array>
136
- </Set>
137
-
138
- <Ref id="RequestLog">
139
- <Set name="requestLog">
140
- <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
141
- <Arg>log/jetty.request.log</Arg>
142
- <Set name="append">true</Set>
143
- <Set name="extended">false</Set>
144
- <Set name="LogTimeZone">GMT</Set>
145
- </New>
146
- </Set>
147
- </Ref>
148
-
149
- <Set name="stopAtShutdown">true</Set>
150
- <Set name="sendServerVersion">true</Set>
151
-
152
- </Configure>
153
- END_OF_JETTY_XML
154
-
155
- erb = ERB.new(template)
156
- erb.result(binding)
157
- end
158
-
159
- end #class
160
- end #module
@@ -1,35 +0,0 @@
1
- require 'logger'
2
-
3
- module War
4
-
5
- # A wrapper class for the 'logger' ruby lib
6
- # logging levels are (default: INFO)
7
- # Logger::Severity::DEBUG
8
- # Logger::Severity::INFO
9
- # Logger::Severity::WARN
10
- # Logger::Severity::FATAL
11
- # Logger::Severity::UNKNOWN
12
-
13
- class WLog
14
- @@logger_inst = Logger.new(STDOUT)
15
- #@@logger_inst.level = Logger::Severity::DEBUG
16
- @@logger_inst.level = Logger::Severity::INFO
17
-
18
- def self.level=(level_req)
19
- @@logger_inst.level = level_req
20
- end
21
-
22
- Logger::Severity.constants.each { |level|
23
- level.downcase!
24
- instance_eval %{
25
- def #{level}(text='')
26
- @@logger_inst.send("#{level}","#{level}: " + text)
27
- end
28
- }
29
- }
30
- end
31
-
32
- end
33
-
34
-
35
-
@@ -1,324 +0,0 @@
1
- #
2
- # Configuration for building a war file
3
- # By Robert Egglestone
4
- # Fausto Lelli
5
- #
6
- require 'util'
7
-
8
- module War
9
-
10
-
11
- class Configuration
12
- include Singleton
13
-
14
- # the name of the project
15
- attr_accessor :name
16
- # the path and name of the war_file
17
- attr_accessor :war_file
18
- # path to the staging directory
19
- attr_accessor :staging
20
- # a list of patterns of excluded files
21
- attr_accessor :excludes
22
- # project java libraries are stored here
23
- attr_accessor :local_java_lib
24
- # servlet to use for running Rails
25
- attr_accessor :servlet
26
- # enable jndi support?
27
- attr_accessor :datasource_jndi
28
- attr_accessor :datasource_jndi_name
29
-
30
- # external locations
31
- attr_accessor :jruby_home
32
- attr_accessor :maven_local_repository
33
- attr_accessor :maven_remote_repository
34
-
35
- # compile ruby files? currently only preparses files, but has problems with paths
36
- attr_accessor :compile_ruby
37
- # keep source if compiling ruby files?
38
- attr_accessor :keep_source
39
- # if you set this to false gems will fail to load if their dependencies aren't available
40
- attr_accessor :add_gem_dependencies
41
- # standalone?
42
- attr_accessor :standalone
43
- # rails environment?
44
- attr_accessor :rails_env
45
- # rails environment to use when running with an embedded server?
46
- attr_accessor :rails_env_embedded
47
-
48
- # files to include in the package
49
- attr_accessor :files
50
- # java libraries to include in the package
51
- attr_accessor :java_libraries
52
- # gem libraries to include in the package
53
- attr_accessor :gem_libraries
54
- # jetty libraries, used for running the war
55
- attr_accessor :jetty_libraries
56
-
57
- # the real separator for the operating system
58
- attr_accessor :os_separator
59
- attr_accessor :os_path_separator
60
-
61
- attr_accessor :jetty_port
62
- attr_accessor :jetty_java_opts
63
-
64
- def initialize
65
-
66
- WLog.debug("initializing configuration ...")
67
- # default internal locations
68
- @staging = RAILS_ROOT
69
- @excludes = []
70
- @local_java_lib = File.join('lib', 'java')
71
-
72
- # default build properties
73
- @compile_ruby = false
74
- @keep_source = false
75
- @add_gem_dependencies = true
76
- @servlet = 'org.jruby.webapp.RailsServlet'
77
- @rails_env = 'production'
78
- @rails_env_embedded = ENV['RAILS_ENV'] || 'development'
79
- @datasource_jndi = false
80
-
81
- home = ENV['HOME'] || ENV['USERPROFILE']
82
- @jruby_home = ENV['JRUBY_HOME']
83
- @maven_local_repository = ENV['MAVEN2_REPO'] # should be in settings.xml, but I need an override
84
- @maven_local_repository ||= File.join(home, '.m2', 'repository') if home
85
- @maven_remote_repository = 'http://repo1.maven.org/maven2'
86
-
87
- # configured war name, defaults to the same as the ruby webapp
88
- @name = File.basename(File.expand_path(RAILS_ROOT))
89
- @war_file = "#{@name}.war"
90
-
91
- @files = {}
92
-
93
- @java_libraries = {}
94
- # default java libraries
95
- add_library(maven_library('org.jruby', 'jruby-complete', '1.0.3'))
96
- add_library(maven_library('org.jruby.extras', 'goldspike', '1.4'))
97
- add_library(maven_library('javax.activation', 'activation', '1.1'))
98
- add_library(maven_library('commons-pool', 'commons-pool', '1.3'))
99
- add_library(maven_library('bouncycastle', 'bcprov-jdk14', '124'))
100
-
101
- # default gems
102
- @gem_libraries = {}
103
- add_gem('rails', rails_version) unless File.exists?('vendor/rails')
104
- add_gem('activerecord-jdbc-adapter') if Dir['vendor/{gems/,}{activerecord-jdbc-adapter,ActiveRecord-JDBC}'].empty?
105
-
106
- # default jetty libraries
107
- @jetty_libraries = {}
108
- add_jetty_library(maven_library('org.mortbay.jetty', 'start', '6.1.1'))
109
- add_jetty_library(maven_library('org.mortbay.jetty', 'jetty', '6.1.1'))
110
- add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-util', '6.1.1'))
111
- add_jetty_library(maven_library('org.mortbay.jetty', 'servlet-api-2.5', '6.1.1'))
112
- add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-plus', '6.1.1'))
113
- add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-naming', '6.1.1'))
114
-
115
- # default jetty settings
116
- @jetty_port = 8080
117
- @jetty_java_opts = ENV['JAVA_OPTS'] || ''
118
-
119
- # separators
120
- if RUBY_PLATFORM =~ /(mswin)|(cygwin)/i # watch out for darwin
121
- @os_separator = '\\'
122
- @os_path_separator = ';'
123
- elsif RUBY_PLATFORM =~ /java/i
124
- @os_separator = java.io.File.separator
125
- @os_path_separator = java.io.File.pathSeparator
126
- else
127
- @os_separator = File::SEPARATOR
128
- @os_path_separator = File::PATH_SEPARATOR
129
- end
130
-
131
- # load user configuration
132
- WLog.debug("loading user configuration ...")
133
- load_user_configuration
134
- end # initialize
135
-
136
- def exclude_files(pattern)
137
- @excludes << pattern
138
- end
139
-
140
- def datasource_jndi_name
141
- @datasource_jndi_name || "jdbc/#{name}"
142
- end
143
-
144
- # Get the rails version from environment.rb, or default to the latest version
145
- # This can be overriden by using add_gem 'rails', ...
146
- def rails_version
147
- environment_without_comments = IO.readlines(File.join('config', 'environment.rb')).reject { |l| l =~ /^#/ }.join
148
- environment_without_comments =~ /[^#]RAILS_GEM_VERSION = '([\d.]+)'/
149
- version = $1
150
- version ? "= #{version}" : nil
151
- end
152
-
153
- def load_user_configuration
154
- user_config = ENV['WAR_CONFIG'] || File.join(RAILS_ROOT, 'config', 'war.rb')
155
- if File.exists?(user_config)
156
- begin
157
- War::Configuration::DSL.evaluate(user_config, self)
158
- rescue => e
159
- puts e.backtrace.join("\n")
160
- WLog.error("Error reading user configuration (#{e.message}), using defaults")
161
- end
162
- end
163
- end
164
-
165
- def java_library(name, version)
166
- WLog.debug("add java library : " + name + " " + version)
167
- # check local sources first, then the list
168
- JavaLibrary.new(name, version, self)
169
- end
170
-
171
- def maven_library(group, name, version)
172
- WLog.debug("add maven library : " + group + " " + name + " " + version)
173
- #locations = maven_locations(group, name, version)
174
- MavenLibrary.new(group, name, version, self)
175
- end
176
-
177
- def add_library(lib)
178
- @java_libraries[lib.name] = lib
179
- end
180
-
181
- def add_file(name, info)
182
- @files[name] = {:location => "war/#{name}", :directory => :classes }.merge(info)
183
- end
184
-
185
- def add_jetty_library(lib)
186
- @jetty_libraries[lib.name] = lib
187
- end
188
-
189
- def add_gem(name, match_version=nil)
190
- @gem_libraries[name] = match_version
191
- end
192
-
193
- def remove_gem(name)
194
- @gem_libraries.delete(name)
195
- end
196
-
197
-
198
- # This class is responsable for loading the war.rb dsl and parsing it to
199
- # evaluated War::Configuration
200
- # <note>will need to readjust this package impl </note>
201
- class DSL
202
-
203
- # saves internally the parsed result
204
- attr_accessor :result
205
-
206
- def initialize (configuration)
207
- @result = configuration
208
- end
209
-
210
- # method hook for name property
211
- def war_file(*val)
212
- WLog.warn "property 'war_file' takes only one argument" if val.size > 1
213
- @result.war_file = val[0]
214
- end
215
-
216
- def exclude_files(*val)
217
- WLog.warn "property 'exclude_files' takes only one argument" if val.size > 1
218
- @result.exclude_files(val[0])
219
- end
220
-
221
- def servlet(*val)
222
- WLog.warn "property 'servlet' takes only one argument" if val.size > 1
223
- @result.servlet = val[0]
224
- end
225
-
226
- def compile_ruby(*val)
227
- WLog.warn "property 'compile_ruby' takes only one argument" if val.size > 1
228
- unless is_either_true_or_false?(val[0])
229
- WLog.warn "property 'compile_ruby' must be either true or false"
230
- return
231
- end
232
- @result.compile_ruby = val[0]
233
- end
234
-
235
- def add_gem_dependencies(*val)
236
- WLog.warn "property 'add_gem_dependencies' takes only one argument" if val.size > 1
237
- unless is_either_true_or_false?(val[0])
238
- WLog.warn "property 'add_gem_dependencies' must be either true or false"
239
- return
240
- end
241
- @result.add_gem_dependencies = val[0]
242
- end
243
-
244
- def keep_source(*val)
245
- WLog.warn "property 'keep_source' takes only one argument" if val.size > 1
246
- unless is_either_true_or_false?(val[0])
247
- WLog.warn "property 'keep_source' must be either true or false"
248
- return
249
- end
250
- @result.keep_source = val[0]
251
- end
252
-
253
- def add_file(name, config={})
254
- @result.add_file(name, config)
255
- end
256
-
257
- def add_gem(*val)
258
- WLog.warn "add_gem takes at most two arguments" if val.size > 2
259
- @result.add_gem(val[0], val[1])
260
- end
261
-
262
- def datasource_jndi(*val)
263
- WLog.warn "property 'datasource_jndi' takes only one argument" if val.size > 1
264
- unless is_either_true_or_false?(val[0])
265
- WLog.warn "property 'datasource_jndi' must be either true or false"
266
- return
267
- end
268
- @result.datasource_jndi = val[0]
269
- end
270
-
271
- def datasource_jndi_name(*val)
272
- WLog.warn "datasource_jndi_name takes at most one argument" if val.size > 1
273
- @result.datasource_jndi_name = val[0]
274
- end
275
-
276
- def staging(*val)
277
- puts "Warning: staging takes only one argument" if val.size > 1
278
- @result.staging = val[0]
279
- end
280
-
281
- # method hook for library property
282
- def include_library(name, version)
283
- begin
284
- @result.add_library(@result.java_library(name, version))
285
- rescue
286
- WLog.warn "couldn't load library #{name}-#{version}.jar, check library definition in the config file"
287
- WLog.debug $!
288
- end
289
- end
290
-
291
- # method hook for maven library property
292
- def maven_library(group, name, version)
293
- begin
294
- @result.add_library(@result.maven_library(group, name, version))
295
- rescue
296
- WLog.warn "couldn't load maven library #{name}, check library definition in the config file"
297
- WLog.debug $!
298
- end
299
- end
300
-
301
- # method hook for default behaviour when an unknown property
302
- # is met in the dsl. By now, just ignore it and print a warning
303
- # message
304
- def method_missing(name, *args)
305
- WLog.warn "property '#{name}' in config file not defined, ignoring it ..."
306
- end
307
-
308
- # main parsing method. pass the file name for the dsl and the configuration
309
- # reference to evaluate against.
310
- def self.evaluate(filename, configuration)
311
- raise "file #{filename} not found " unless File.exists?(filename)
312
- dsl = new(configuration)
313
- dsl.instance_eval(File.read(filename) , filename)
314
- dsl
315
- end
316
-
317
- # utility
318
- def is_either_true_or_false?(obj)
319
- obj.class == TrueClass or obj.class == FalseClass
320
- end
321
- end #class DSL
322
-
323
- end #class
324
- end #module