trinidad 1.3.4 → 1.3.5

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/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :gemcutter
2
+
3
+ gemspec :name => "trinidad"
@@ -1,3 +1,11 @@
1
+ == Trinidad 1.3.5 (2012-04-04)
2
+
3
+ * Correctly detect :rackup from main config for web apps (#66)
4
+ * Rearrange trinidad.gemspec to be (always) usable with Bundler's :git paths.
5
+ * Use out/err streams from the Ruby runtime for logging instead of the default console log handler.
6
+ * Make sure tomcat exits on initialization failure.
7
+ * Yield from block passed to Trinidad's Rack::Handler
8
+
1
9
  == Trinidad 1.3.4 (2012-02-20)
2
10
 
3
11
  * Do not explicitely load rack/handler/trinidad.rb, it solves load issues with trinidad_init_services.
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ def version(file, constant)
5
+ line = File.read(file)[/^\s*#{constant}\s*=\s*.*/]
6
+ line.match(/.*#{constant}\s*=\s*['"](.*)['"]/)[1]
7
+ end
8
+
9
+ def build(gemspec_file, gem_file)
10
+ mkdir_p 'pkg'
11
+ sh "gem build #{gemspec_file}"
12
+ mv gem_file, 'pkg'
13
+ end
14
+
15
+ def release(name, gem_file, version)
16
+ unless `git branch` =~ /^\* master$/
17
+ puts "You must be on the master branch to release!"
18
+ exit!
19
+ end
20
+ sh "git commit --allow-empty -a -m 'Release #{name} #{version}'"
21
+ sh "git tag v#{name}-#{version}"
22
+ sh "git push origin master"
23
+ sh "git push --tags"
24
+ sh "gem push pkg/#{gem_file}"
25
+ end
26
+
27
+ {
28
+ :build => 'Build all Trinidad gems',
29
+ :install => 'Install all Trinidad gems',
30
+ :release => 'Release all Trinidad gems'
31
+ }.each do |task, desc|
32
+ desc desc
33
+ task task => ["trinidad_jars:#{task}", "trinidad:#{task}"]
34
+ end
35
+
36
+ require 'rspec/core/rake_task'
37
+
38
+ RSpec::Core::RakeTask.new(:spec) do |spec|
39
+ spec.rspec_opts = ['--color', "--format documentation"]
40
+ end
41
+
42
+ task :default => :spec
@@ -13,11 +13,12 @@ module Rack
13
13
  opts = parse_options(options)
14
14
 
15
15
  servlet = create_servlet(app)
16
-
17
16
  opts[:servlet] = {:instance => servlet, :name => 'RackServlet'}
18
17
 
19
- ::Trinidad::CommandLineParser.new.load_configuration(opts)
20
- ::Trinidad::Server.new.start
18
+ ::Trinidad::CommandLineParser.load(opts)
19
+ server = ::Trinidad::Server.new
20
+ yield server if block_given?
21
+ server.start
21
22
  end
22
23
 
23
24
  def self.valid_options
@@ -40,6 +41,7 @@ module Rack
40
41
  threads = (opts[:threads] || '1:1').split(':')
41
42
  opts[:port] ||= 3000
42
43
  opts[:address] ||= opts[:host] || 'localhost'
44
+ # NOTE: this is currently not supported by embedded Dispatcher and has no effect :
43
45
  opts[:jruby_min_runtimes], opts[:jruby_max_runtimes] = threads[0].to_i, threads[1].to_i
44
46
  opts
45
47
  end
@@ -2,6 +2,7 @@ require 'java'
2
2
 
3
3
  require 'jruby-rack'
4
4
 
5
+ require 'trinidad/version'
5
6
  require 'trinidad/core_ext'
6
7
  require 'trinidad/extensions'
7
8
  require 'trinidad/configuration'
@@ -18,7 +19,3 @@ require 'trinidad/web_app'
18
19
  require 'trinidad/rails_web_app'
19
20
  require 'trinidad/rackup_web_app'
20
21
  require 'trinidad/war_web_app'
21
-
22
- module Trinidad
23
- VERSION = '1.3.4'
24
- end
@@ -8,6 +8,10 @@ module Trinidad
8
8
  CommandLineParser.new.parse!(argv)
9
9
  end
10
10
 
11
+ def self.load(options = {})
12
+ CommandLineParser.new.load!(options)
13
+ end
14
+
11
15
  def initialize
12
16
  @default_options = {}
13
17
  end
@@ -20,10 +24,10 @@ module Trinidad
20
24
  exit(1)
21
25
  end
22
26
 
23
- load_configuration(default_options)
27
+ load!(default_options)
24
28
  end
25
29
 
26
- def load_configuration(options)
30
+ def load!(options)
27
31
  base_dir = options[:web_app_dir] || Dir.pwd
28
32
  config = options.delete(:config) || Dir.glob(File.join(base_dir, 'config', 'trinidad.{yml,rb}')).first
29
33
  if config and config = File.expand_path(config, base_dir)
@@ -42,6 +46,7 @@ module Trinidad
42
46
 
43
47
  options
44
48
  end
49
+ alias_method :load_configuration, :load!
45
50
 
46
51
  def yaml_configuration?(config)
47
52
  config && File.exist?(config) && config =~ /\.yml$/
@@ -9,11 +9,6 @@ module Trinidad
9
9
  self.configuration
10
10
  end
11
11
 
12
- # test only purposes
13
- def self.cleanup
14
- self.configuration = nil
15
- end
16
-
17
12
  class Configuration
18
13
  attr_accessor :port, :address, :environment, :context_path, :libs_dir, :classes_dir,
19
14
  :default_web_xml, :log, :jruby_min_runtimes, :jruby_max_runtimes,
@@ -49,7 +49,14 @@ module Trinidad
49
49
 
50
50
  jlogging = java.util.logging
51
51
 
52
- log_handler = jlogging.FileHandler.new(log_path, true)
52
+ file_handler = jlogging.FileHandler.new(log_path, true)
53
+
54
+ out_handler = jlogging.ConsoleHandler.new
55
+ out_handler.set_output_stream JRuby.runtime.out
56
+
57
+ err_handler = jlogging.ConsoleHandler.new
58
+ err_handler.set_output_stream JRuby.runtime.err
59
+
53
60
  logger = jlogging.Logger.get_logger("")
54
61
 
55
62
  log_level = @webapp.log
@@ -60,7 +67,12 @@ module Trinidad
60
67
 
61
68
  level = jlogging.Level.parse(log_level)
62
69
 
63
- logger.add_handler(log_handler)
70
+ console_handler = logger.handlers.first
71
+ logger.remove_handler(console_handler)
72
+
73
+ logger.add_handler(file_handler)
74
+ logger.add_handler(out_handler)
75
+ logger.add_handler(err_handler)
64
76
 
65
77
  logger.handlers.each do |handler|
66
78
  handler.level = level
@@ -11,11 +11,13 @@ module Trinidad
11
11
  end
12
12
 
13
13
  def load_config(config)
14
- @config = config
15
- add_default_web_app!(config)
14
+ add_default_web_app! config
15
+ @config = config.freeze
16
16
  end
17
17
 
18
18
  def load_tomcat_server
19
+ load_default_system_properties
20
+
19
21
  @tomcat = Trinidad::Tomcat::Tomcat.new
20
22
  @tomcat.base_dir = Dir.pwd
21
23
  @tomcat.hostname = @config[:address] || 'localhost'
@@ -39,9 +41,8 @@ module Trinidad
39
41
 
40
42
  set_default_host
41
43
  elsif @config[:web_apps]
42
- # create the hosts when they are specified for each app into
43
- # web_apps. We must create them before creating the
44
- # applications.
44
+ # create the hosts when they are specified for each app into web_apps.
45
+ # We must create them before creating the applications.
45
46
  @config[:web_apps].each do |name, app_config|
46
47
  if host_names = app_config.delete(:hosts)
47
48
  dir = app_config[:web_app_dir] || Dir.pwd
@@ -60,7 +61,7 @@ module Trinidad
60
61
  apps = []
61
62
  apps << create_from_web_apps
62
63
  apps << create_from_apps_base
63
-
64
+
64
65
  apps.flatten.compact
65
66
  end
66
67
 
@@ -218,6 +219,10 @@ module Trinidad
218
219
  @tomcat.destroy
219
220
  end
220
221
 
222
+ def load_default_system_properties
223
+ java.lang.System.set_property("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", 'true')
224
+ end
225
+
221
226
  private
222
227
 
223
228
  def create_host(apps_base, names)
@@ -0,0 +1,3 @@
1
+ module Trinidad
2
+ VERSION = '1.3.5'
3
+ end
@@ -61,18 +61,18 @@ module Trinidad
61
61
  )
62
62
  end
63
63
 
64
- def public_root
65
- @app_config[:public] || @config[:public] || 'public'
66
- end
67
-
68
- %w{context_path web_app_dir libs_dir classes_dir default_web_xml
69
- jruby_min_runtimes jruby_max_runtimes rackup log}.each do |method_name|
64
+ %w{ context_path web_app_dir libs_dir classes_dir default_web_xml
65
+ jruby_min_runtimes jruby_max_runtimes rackup log }.each do |method_name|
70
66
  define_method method_name do
71
67
  sym = method_name.to_sym
72
68
  @app_config[sym] || @config[sym]
73
69
  end
74
70
  end
75
71
 
72
+ def public_root; @app_config[:public] || @config[:public] || 'public'; end
73
+ def environment; @app_config[:environment] || @config[:environment] || 'development'; end
74
+ def work_dir; @app_config[:work_dir] || @config[:work_dir] || web_app_dir; end
75
+
76
76
  def extensions
77
77
  @extensions ||= begin
78
78
  extensions = @config[:extensions] || {}
@@ -82,8 +82,6 @@ module Trinidad
82
82
  end
83
83
 
84
84
  def war?; WebApp.war?(app_config); end
85
- def work_dir; @app_config[:work_dir] || @config[:work_dir] || web_app_dir; end
86
- def environment; @app_config[:environment] || @config[:environment] || 'development'; end
87
85
 
88
86
  def solo?
89
87
  !self.is_a?(WarWebApp) && @app_config[:solo]
@@ -147,12 +145,14 @@ module Trinidad
147
145
  app_config[:jruby_min_runtimes] = 1
148
146
  app_config[:jruby_max_runtimes] = 1
149
147
  end
150
-
148
+
149
+ rackup = config[:rackup] || 'config.ru'
150
+ app_config[:web_app_dir] ||= config[:web_app_dir] || Dir.pwd
151
151
  # Check for rackup (but still use config/environment.rb for Rails 3)
152
- if !app_config[:rackup] && !config[:rackup] &&
153
- File.exists?("#{app_config[:web_app_dir]}/config.ru") &&
154
- !File.exists?("#{app_config[:web_app_dir]}/config/environment.rb")
155
- app_config[:rackup] = 'config.ru'
152
+ if !app_config[:rackup] &&
153
+ File.exists?(File.join(app_config[:web_app_dir], rackup)) &&
154
+ !File.exists?(File.join(app_config[:web_app_dir], 'config/environment.rb'))
155
+ app_config[:rackup] = rackup
156
156
  end
157
157
  end
158
158
 
@@ -0,0 +1,44 @@
1
+ require 'open-uri'
2
+ require 'tmpdir'
3
+
4
+ namespace :tomcat do
5
+
6
+ TOMCAT_CORE_PATH = File.expand_path('../../trinidad-libs/tomcat-core.jar', __FILE__)
7
+ TOMCAT_MAVEN_REPO = 'http://repo2.maven.org/maven2/org/apache/tomcat'
8
+
9
+ tomcat = "#{TOMCAT_MAVEN_REPO}/embed/tomcat-embed-core/%s/tomcat-embed-core-%s.jar"
10
+ tomcat_jasper = "#{TOMCAT_MAVEN_REPO}/embed/tomcat-embed-jasper/%s/tomcat-embed-jasper-%s.jar"
11
+ tomcat_logging = "#{TOMCAT_MAVEN_REPO}/embed/tomcat-embed-logging-log4j/%s/tomcat-embed-logging-log4j-%s.jar"
12
+
13
+ dependencies = [tomcat, tomcat_jasper, tomcat_logging]
14
+
15
+ desc "Updates Tomcat to a given version"
16
+ task :update, :version do |task, args|
17
+ tomcat_version = [args[:version]] * 2
18
+
19
+ Dir.chdir(Dir.tmpdir) do
20
+ dependencies.each do |dependency|
21
+ dependency_path = dependency % tomcat_version
22
+ dependency_name = dependency_path.split('/').last
23
+
24
+ # dowload dependencies
25
+ puts "downloading #{dependency_path}"
26
+ file = open(dependency_path)
27
+ %x{jar -xf #{file.path}}
28
+ end
29
+
30
+ # build the jar again
31
+ puts "building the tomcat's core jar"
32
+ %x{jar -cvf #{TOMCAT_CORE_PATH} META-INF javax org}
33
+ end
34
+
35
+ puts "updating tomcat's version number to #{tomcat_version.first}"
36
+ path = File.expand_path('../../lib/trinidad/jars.rb', __FILE__)
37
+ file = File.read(path)
38
+ file.gsub!(/TOMCAT_VERSION = '(.+)'/, "TOMCAT_VERSION = '#{tomcat_version.first}'")
39
+ File.open(path, 'w') { |io| io.write(file) }
40
+
41
+ puts "DONE - Tomcat's version has been updated succesfully, please build Trinidad again."
42
+ end
43
+
44
+ end
@@ -0,0 +1,26 @@
1
+ namespace :trinidad do
2
+
3
+ def trinidad_version
4
+ version("lib/trinidad/version.rb", 'VERSION')
5
+ end
6
+
7
+ def trinidad_gem_file
8
+ "trinidad-#{trinidad_version}.gem"
9
+ end
10
+
11
+ desc "Build trinidad gem"
12
+ task :build do
13
+ build('trinidad.gemspec', trinidad_gem_file)
14
+ end
15
+
16
+ desc "Install trinidad gem"
17
+ task :install => :build do
18
+ sh "gem install pkg/#{trinidad_gem_file}"
19
+ end
20
+
21
+ desc "Release trinidad gem"
22
+ task :release => :build do
23
+ release('trinidad', trinidad_gem_file, trinidad_version)
24
+ end
25
+
26
+ end
@@ -0,0 +1,26 @@
1
+ namespace :trinidad_jars do
2
+
3
+ def trinidad_jars_version
4
+ version("lib/trinidad/jars.rb", 'TRINIDAD_JARS_VERSION')
5
+ end
6
+
7
+ def trinidad_jars_gem_file
8
+ "trinidad_jars-#{trinidad_jars_version}.gem"
9
+ end
10
+
11
+ desc "Build trinidad_jars gem"
12
+ task :build do
13
+ build('trinidad_jars.gemspec', trinidad_jars_gem_file)
14
+ end
15
+
16
+ desc "Install trinidad_jars gem"
17
+ task :install => :build do
18
+ sh "gem install pkg/#{trinidad_jars_gem_file}"
19
+ end
20
+
21
+ desc "Release trinidad_jars gem"
22
+ task :release => :build do
23
+ release('trinidad_jars', trinidad_jars_gem_file, trinidad_jars_version)
24
+ end
25
+
26
+ end
@@ -0,0 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'trinidad/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.specification_version = 2 if s.respond_to? :specification_version=
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.rubygems_version = '1.3.5'
9
+
10
+ s.name = 'trinidad'
11
+ s.rubyforge_project = 'trinidad'
12
+ s.version = Trinidad::VERSION
13
+
14
+ s.summary = "Simple library to run rails applications into an embedded Tomcat"
15
+ s.description = "Trinidad allows you to run a rails or rackup applications within an embedded Apache Tomcat container"
16
+
17
+ s.authors = ["David Calavera"]
18
+ s.email = 'calavera@apache.org'
19
+ s.homepage = 'http://github.com/trinidad/trinidad'
20
+
21
+ s.require_paths = %w[lib]
22
+ s.executables = ["trinidad"]
23
+ s.default_executable = 'trinidad'
24
+
25
+ s.rdoc_options = ["--charset=UTF-8"]
26
+ s.extra_rdoc_files = %w[README.md LICENSE]
27
+
28
+ s.add_dependency('trinidad_jars', ">= 1.0.2")
29
+ s.add_dependency('jruby-rack', ">= 1.1.5")
30
+
31
+ s.add_development_dependency('rack')
32
+ s.add_development_dependency('rake')
33
+ s.add_development_dependency('rspec', '~> 2.7')
34
+ s.add_development_dependency('mocha')
35
+ s.add_development_dependency('fakefs', '>= 0.4.0')
36
+
37
+ s.files = `git ls-files`.split("\n").sort.
38
+ reject { |file| file =~ /^\./ }. # .gitignore, .travis.yml
39
+ # TODO backward compatibility - include no spec files ?!
40
+ reject { |file| file =~ /^spec\// }.
41
+ # reject trinidad_jars.gemspec files :
42
+ reject { |file| file == 'trinidad_jars.gemspec' ||
43
+ file == 'lib/trinidad/jars.rb' ||
44
+ file =~ /^trinidad-libs\// }
45
+
46
+ s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
47
+
48
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trinidad
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.4
5
+ version: 1.3.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Calavera
@@ -10,74 +10,85 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-20 00:00:00 Z
13
+ date: 2012-04-04 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: trinidad_jars
17
- version_requirements: &id001 !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
18
19
  none: false
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 1.0.1
23
- requirement: *id001
24
- prerelease: false
23
+ version: 1.0.2
25
24
  type: :runtime
25
+ version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: jruby-rack
28
- version_requirements: &id002 !ruby/object:Gem::Requirement
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
29
30
  none: false
30
31
  requirements:
31
32
  - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: 1.1.1
34
- requirement: *id002
35
- prerelease: false
34
+ version: 1.1.5
36
35
  type: :runtime
36
+ version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rack
39
- version_requirements: &id003 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ">="
43
44
  - !ruby/object:Gem::Version
44
45
  version: "0"
45
- requirement: *id003
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
46
50
  prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
47
57
  type: :development
58
+ version_requirements: *id004
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: rspec
50
- version_requirements: &id004 !ruby/object:Gem::Requirement
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
51
63
  none: false
52
64
  requirements:
53
65
  - - ~>
54
66
  - !ruby/object:Gem::Version
55
67
  version: "2.7"
56
- requirement: *id004
57
- prerelease: false
58
68
  type: :development
69
+ version_requirements: *id005
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: mocha
61
- version_requirements: &id005 !ruby/object:Gem::Requirement
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
62
74
  none: false
63
75
  requirements:
64
76
  - - ">="
65
77
  - !ruby/object:Gem::Version
66
78
  version: "0"
67
- requirement: *id005
68
- prerelease: false
69
79
  type: :development
80
+ version_requirements: *id006
70
81
  - !ruby/object:Gem::Dependency
71
82
  name: fakefs
72
- version_requirements: &id006 !ruby/object:Gem::Requirement
83
+ prerelease: false
84
+ requirement: &id007 !ruby/object:Gem::Requirement
73
85
  none: false
74
86
  requirements:
75
87
  - - ">="
76
88
  - !ruby/object:Gem::Version
77
89
  version: 0.4.0
78
- requirement: *id006
79
- prerelease: false
80
90
  type: :development
91
+ version_requirements: *id007
81
92
  description: Trinidad allows you to run a rails or rackup applications within an embedded Apache Tomcat container
82
93
  email: calavera@apache.org
83
94
  executables:
@@ -88,28 +99,35 @@ extra_rdoc_files:
88
99
  - README.md
89
100
  - LICENSE
90
101
  files:
91
- - bin/trinidad
92
- - lib/trinidad.rb
102
+ - Gemfile
93
103
  - History.txt
94
104
  - LICENSE
95
105
  - README.md
106
+ - Rakefile
107
+ - bin/trinidad
96
108
  - lib/rack/handler/trinidad.rb
109
+ - lib/trinidad.rb
97
110
  - lib/trinidad/command_line_parser.rb
98
111
  - lib/trinidad/configuration.rb
99
112
  - lib/trinidad/core_ext.rb
100
113
  - lib/trinidad/extensions.rb
114
+ - lib/trinidad/lifecycle/lifecycle_listener_base.rb
115
+ - lib/trinidad/lifecycle/lifecycle_listener_default.rb
116
+ - lib/trinidad/lifecycle/lifecycle_listener_host.rb
117
+ - lib/trinidad/lifecycle/lifecycle_listener_war.rb
118
+ - lib/trinidad/lifecycle/takeover.rb
101
119
  - lib/trinidad/log_formatter.rb
102
120
  - lib/trinidad/rackup_web_app.rb
103
121
  - lib/trinidad/rails_web_app.rb
104
122
  - lib/trinidad/server.rb
123
+ - lib/trinidad/version.rb
105
124
  - lib/trinidad/war_web_app.rb
106
125
  - lib/trinidad/web_app.rb
107
- - lib/trinidad/lifecycle/lifecycle_listener_base.rb
108
- - lib/trinidad/lifecycle/lifecycle_listener_default.rb
109
- - lib/trinidad/lifecycle/lifecycle_listener_host.rb
110
- - lib/trinidad/lifecycle/lifecycle_listener_war.rb
111
- - lib/trinidad/lifecycle/takeover.rb
112
- homepage: http://github.com/calavera/trinidad
126
+ - rakelib/tomcat.rake
127
+ - rakelib/trinidad.rake
128
+ - rakelib/trinidad_jars.rake
129
+ - trinidad.gemspec
130
+ homepage: http://github.com/trinidad/trinidad
113
131
  licenses: []
114
132
 
115
133
  post_install_message:
@@ -122,9 +140,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
140
  requirements:
123
141
  - - ">="
124
142
  - !ruby/object:Gem::Version
125
- hash: 2
126
- segments:
127
- - 0
128
143
  version: "0"
129
144
  required_rubygems_version: !ruby/object:Gem::Requirement
130
145
  none: false