Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit ac4ff2644de0f63b5b42b66b5f80f6554d94da59 @calavera calavera committed Jul 3, 2009
@@ -0,0 +1,5 @@
+README.rdoc
+lib/**/*.rb
+bin/*
+features/**/*.feature
+LICENSE
@@ -0,0 +1,7 @@
+*.sw?
+.DS_Store
+coverage
+rdoc
+pkg
+nbproject
+.idea
@@ -0,0 +1,19 @@
+== 0.3.0 (?)
+
+* project renamed due to tomcat legal issues
+
+== 0.2.0 (2009-06-23)
+
+* custom configuration from a yaml file
+* load options from a custom web.xml
+
+== 0.1.2
+
+* Autoload application custom jars and classes.
+* Added some specs.
+* Server refactor.
+
+== 0.1
+
+* Initial release.
+* Running default rails applications.
26 LICENSE
@@ -0,0 +1,26 @@
+== Trinidad
+
+Copyright (c) 2009 David Calavera
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+== Additional Bundled Software
+
+Apache Tomcat is licensed according to the terms of Apache License, Version 2.0 (current). See http://www.apache.org/licenses/LICENSE-2.0 for details.
@@ -0,0 +1,34 @@
+= trinidad
+
+Trinidad allows you to run a rails application within an embedded Apache Tomcat container.
+
+This project was initially called "Tomcat-rails" but due to legal issues with the ASF and the Tomcat trademark it has been renamed.
+
+== INSTALL:
+
+ jgem install trinidad
+ jgem install calavera-trinidad -s http://gems.github.com
+
+== USAGE:
+
+ cd myrailsapp
+ jruby -S trinidad
+
+== CONFIGURATION:
+
+Trinidad allows you to configure some parameters when the server is started from the command line, the following is a list of the currently supported options:
+
+ * -p, --port PORT => port to bind to.
+ * -e, --env ENVIRONMENT => rails environment.
+ * -c, --context CONTEXT => application context path.
+ * --lib, --jars LIBS_DIR => directory containing jars.
+ * --classes CLASSES_DIR => directory containing classes.
+
+The server can also be configured from a yaml file. If a file is not especified, the server tries to load the file <em>config/tomcat.yml</em>. Within this file you can add other options like jruby.min.runtimes(:jruby_min_runtimes) or jruby.max.runtimes(:jruby_max_runtimes).
+
+ jruby -S trinidad -f
+ jruby -S trinidad --config my_custom_configuration.yml
+
+== Copyright
+
+Copyright (c) 2009 David Calavera<calavera@apache.org>. See LICENSE for details.
@@ -0,0 +1,51 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "trinidad"
+ gem.summary = %Q{Simple library to run rails applications into an embedded Tomcat}
+ gem.email = "david.calavera@gmail.com"
+ gem.homepage = "http://calavera.github.com/trinidad"
+ gem.authors = ["David Calavera"]
+
+ gem.files = FileList['bin/*', 'lib/**/*.rb', 'trinidad-libs/*.jar', 'History.txt', 'LICENSE', 'Rakefile', 'README.rdoc', 'VERSION']
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ end
+
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
+
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new(:spec) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.spec_opts = ['--options', "spec/spec.opts"]
+ spec.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+Spec::Rake::SpecTask.new(:rcov) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.spec_opts = ['--options', "spec/spec.opts"]
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
+end
+
+task :default => :spec
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ if File.exist?('VERSION.yml')
+ config = YAML.load(File.read('VERSION.yml'))
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
+ else
+ version = ""
+ end
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "trinidad #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
@@ -0,0 +1,5 @@
+== TODO
+
+* Add more tests!!!!!!!
+* Add rdocs
+* configure it from warbler
@@ -0,0 +1 @@
+0.3.0
@@ -0,0 +1,9 @@
+#!/usr/bin/env jruby
+
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+$:.unshift(File.dirname(__FILE__) + '/../trinidad-libs')
+
+require "trinidad"
+
+opts = Trinidad::CommandLineParser.parse
+Trinidad::Server.new(opts).start
@@ -0,0 +1,14 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+require "java"
+require 'rubygems'
+
+require 'trinidad/command_line_parser'
+require 'trinidad/jars'
+require 'trinidad/server'
+require 'trinidad/web_app'
+
+module Trinidad
+ TRINIDAD_LIBS = File.dirname(__FILE__) + "/../trinidad-libs" unless defined?(TRINIDAD_LIBS)
+end
@@ -0,0 +1,66 @@
+module Trinidad
+ require 'optparse'
+
+ class CommandLineParser
+ def self.parse
+ default_options = {
+ :port => 3000,
+ :environment => 'development',
+ :context_path => '/',
+ :libs_dir => 'lib',
+ :classes_dir => 'classes',
+ :config => 'config/tomcat.yml'
+ }
+
+ parser = OptionParser.new do |opts|
+ opts.banner = 'Trinidad server default options:'
+ opts.separator ''
+
+ opts.on('-e', '--env ENVIRONMENT', 'Rails environment',
+ "default: #{default_options[:environment]}") do |v|
+ default_options[:environment] = v
+ end
+
+ opts.on('-p', '--port PORT', 'Port to bind to',
+ "default: #{default_options[:port]}") do |v|
+ default_options[:port] = v
+ end
+
+ opts.on('-c', '--context CONTEXT_PATH', 'The application context path',
+ "default: #{default_options[:context_path]}") do |v|
+ default_options[:context_path] = v
+ end
+
+ opts.on('--lib', '--jars LIBS_DIR', 'Directory containing jars used by the application',
+ "default: #{default_options[:libs_dir]}") do |v|
+ default_options[:libs_dir] = v
+ end
+
+ opts.on('--classes', '--classes CLASSES_DIR', 'Directory containing classes used by the application',
+ "default: #{default_options[:classes_dir]}") do |v|
+ default_options[:classes_dir] = v
+ end
+
+ opts.on('-f', '--config [CONFIG_FILE]', 'Configuration file',
+ "default: #{default_options[:config]}") do |v|
+ default_options[:config] = v if v
+ default_options.merge! YAML.load_file(default_options[:config])
+ end
+
+ opts.on('-v', '--version', 'display the current version') do
+ puts File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
+ exit
+ end
+
+ opts.on('-h', '--help', 'display the help') do
+ puts opts
+ exit
+ end
+
+ opts.parse!(ARGV)
+ end
+
+ default_options
+ end
+ end
+end
@@ -0,0 +1,26 @@
+module Trinidad
+
+ require "servlet-api-2.5-6.1.14"
+ require "core-3.1.1"
+ require "jsp-api-2.1"
+ require "jsp-2.1"
+ require 'tomcat-core'
+ require 'jetty-util-6.1.14'
+
+ require "jruby-rack-0.9.4"
+
+ module Tomcat
+ include_package 'org.apache.catalina'
+ include_package 'org.apache.catalina.startup'
+ include_package 'org.apache.catalina.core'
+ include_package 'org.apache.catalina.deploy'
+ include_package 'org.apache.catalina.loader'
+
+ include_package 'org.apache.naming.resources'
+ end
+
+ module Rack
+ include_package "org.jruby.rack"
+ include_package "org.jruby.rack.rails"
+ end
+end
@@ -0,0 +1,48 @@
+module Trinidad
+ class Server
+
+ @@defaults = {
+ :environment => 'development',
+ :context_path => '/',
+ :libs_dir => 'lib',
+ :classes_dir => 'classes',
+ :default_web_xml => 'config/web.xml',
+ :port => 3000,
+ :jruby_min_runtimes => 1,
+ :jruby_max_runtimes => 5
+ }
+
+ def initialize(config = {})
+ load_config(config)
+ load_tomcat_server
+ create_web_app
+ end
+
+ def load_config(config)
+ @config = @@defaults.merge!(config)
+ @config[:web_app_dir] = Dir.pwd
+ end
+
+ def load_tomcat_server
+ @tomcat = Trinidad::Tomcat::Tomcat.new
+ @tomcat.setPort(@config[:port].to_i)
+ end
+
+ def create_web_app
+ web_app = WebApp.new(@tomcat.addWebapp(@config[:context_path].to_s, @config[:web_app_dir]), @config)
+
+ web_app.load_default_web_xml
+ web_app.add_rack_filter
+ web_app.add_context_loader
+ web_app.add_init_params
+ web_app.add_web_dir_resources
+
+ web_app.add_rack_context_listener
+ end
+
+ def start
+ @tomcat.start
+ @tomcat.getServer().await
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit ac4ff26

Please sign in to comment.