Modified: trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb (730 => 731)
--- trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb 2007-08-31 21:03:58 UTC (rev 730)
+++ trunk/rails-integration/plugins/goldspike-snapshot/lib/war_config.rb 2007-09-02 23:22:52 UTC (rev 731)
@@ -6,8 +6,6 @@
require 'util'
module War
-
-
class Configuration
include Singleton
@@ -60,13 +58,22 @@
attr_accessor :jetty_port
attr_accessor :jetty_java_opts
+
+ # custom tasks to run when assembling the war
+ attr_accessor :custom_tasks
def initialize
-
WLog.debug("initializing configuration ...")
- # default internal locations
- @staging = RAILS_ROOT
+
+ # initialize variables
@excludes = []
+ @files = {}
+ @custom_tasks = []
+
+ # defaults
+ @name = File.basename(File.expand_path(RAILS_ROOT))
+ @war_file = "[EMAIL PROTECTED]"
+ @staging = RAILS_ROOT
@local_java_lib = File.join('lib', 'java')
# default build properties
@@ -82,38 +89,26 @@
@jruby_home = ENV['JRUBY_HOME']
@maven_local_repository = ENV['MAVEN2_REPO'] # should be in settings.xml, but I need an override
@maven_local_repository ||= File.join(home, '.m2', 'repository') if home
- @maven_remote_repository = 'http://www.ibiblio.org/maven2'
+ @maven_remote_repository = 'http://repo1.maven.org/maven2'
- # configured war name, defaults to the same as the ruby webapp
- @name = File.basename(File.expand_path(RAILS_ROOT))
- @war_file = "[EMAIL PROTECTED]"
-
- @files = {}
-
- @java_libraries = {}
# default java libraries
- add_library(maven_library('org.jruby', 'jruby-complete', '1.0.1'))
- add_library(maven_library('org.jruby.extras', 'goldspike', '1.3'))
- add_library(maven_library('javax.activation', 'activation', '1.1'))
- add_library(maven_library('commons-pool', 'commons-pool', '1.3'))
+ @java_libraries = {}
+ add_library('jruby-complete', :version => '1.0.1', :group => 'org.jruby')
+ add_library('goldspike', :version => '1.3', :group => 'org.jruby.extras')
+ add_library('activation', :version => '1.1', :group => 'javax.activation')
+ add_library('commons-pool', :version => '1.3', :group => 'commons-pool')
+ add_library('bcprov-jdk14', :version => '124', :group => 'bouncycastle')
# default gems
@gem_libraries = {}
add_gem('rails', rails_version) unless File.exists?('vendor/rails')
add_gem('ActiveRecord-JDBC') if Dir['vendor/{gems/,}{activerecord-jdbc,ActiveRecord-JDBC}'].empty?
- # default jetty libraries
- @jetty_libraries = {}
- add_jetty_library(maven_library('org.mortbay.jetty', 'start', '6.1.1'))
- add_jetty_library(maven_library('org.mortbay.jetty', 'jetty', '6.1.1'))
- add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-util', '6.1.1'))
- add_jetty_library(maven_library('org.mortbay.jetty', 'servlet-api-2.5', '6.1.1'))
- add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-plus', '6.1.1'))
- add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-naming', '6.1.1'))
-
# default jetty settings
+ @jetty_libraries = {}
@jetty_port = 8080
- @jetty_java_opts = ENV['JAVA_OPTS'] || ''
+ @jetty_java_opts = ENV['JETTY_OPTS'] || ENV['JAVA_OPTS'] || ''
+ jetty_version = '6.1.5'
# separators
if RUBY_PLATFORM =~ /(mswin)|(cygwin)/i # watch out for darwin
@@ -139,6 +134,12 @@
def datasource_jndi_name
@datasource_jndi_name || "jdbc/#{name}"
end
+
+ def jetty_version=(version)
+ for name in %w(start jetty jetty-util jetty-plus jetty-naming servlet-api-2.5) do
+ add_jetty_library(:name => name, :version => version, :group => 'org.mortbay.jetty')
+ end
+ end
# Get the rails version from environment.rb, or default to the latest version
# This can be overriden by using add_gem 'rails', ...
@@ -153,38 +154,67 @@
user_config = ENV['WAR_CONFIG'] || File.join(RAILS_ROOT, 'config', 'war.rb')
if File.exists?(user_config)
begin
- War::Configuration::DSL.evaluate(user_config, self)
+ instance_eval(File.read(user_config), user_config)
rescue => e
+ WLog.error("Error reading user configuration (#{e.message}), using defaults")
puts e.backtrace.join("\n")
- WLog.error("Error reading user configuration (#{e.message}), using defaults")
end
end
end
def java_library(name, version)
- WLog.debug("add java library : " + name + " " + version)
- # check local sources first, then the list
- JavaLibrary.new(name, version, self)
+ # exists for backwards compatibility
+ add_library(name, :version => version)
end
def maven_library(group, name, version)
- WLog.debug("add maven library : " + group + " " + name + " " + version)
- #locations = maven_locations(group, name, version)
- MavenLibrary.new(group, name, version, self)
+ # exists for backwards compatibility
+ add_library(name, :group => group, :version => version)
end
- def add_library(lib)
+ def add_library(*args)
+ properties = {}
+ # optional first arg is name
+ if !args.empty? && args[0].is_a?(String)
+ properties[:name] = args.shift
+ end
+ # followed by a hash of properties
+ if !args.empty?
+ unless args[0].is_a?(Hash)
+ WLog.warn("Skipping add_library due to syntax error: add_library(#{args.join(', ')})")
+ return
+ end
+ properties.merge!(args[0])
+ end
+
+ name = properties[:name]
+ group = properties[:group]
+ version = properties[:version]
+ if group
+ WLog.debug("add maven library: " + group + " " + name + " " + version)
+ lib = MavenLibrary.new(group, name, version, self)
+ else
+ WLog.debug("add java library: " + name + " " + version)
+ lib = JavaLibrary.new(name, version, self)
+ end
+
@java_libraries[lib.name] = lib
end
-
- def add_file(name, info)
- @files[name] = {:location => "war/#{name}", :directory => :classes }.merge(info)
- end
+ def remove_library(name, properties={})
+ # remove a library that matches name and all specified properties
+ @java_libraries.delete_if {|k,v| k == name && v == v.merge(properties) }
+ end
+
def add_jetty_library(lib)
@jetty_libraries[lib.name] = lib
end
+ def remove_jetty_library(name, properties={})
+ # remove a library that matches name and all specified properties
+ @jetty_libraries.delete_if {|k,v| k == name && v == v.merge(properties) }
+ end
+
def add_gem(name, match_version=nil)
@gem_libraries[name] = match_version
end
@@ -193,133 +223,23 @@
@gem_libraries.delete(name)
end
-
- # This class is responsable for loading the war.rb dsl and parsing it to
- # evaluated War::Configuration
- # <note>will need to readjust this package impl </note>
- class DSL
+ def add_file(name, info)
+ @files[name] = {:location => "war/#{name}", :directory => :classes }.merge(info)
+ end
+
+ def remove_file(name)
+ @files.delete_if {|k,v| k == name }
+ end
- # saves internally the parsed result
- attr_accessor :result
+ def add_custom_task(&task)
+ @custom_tasks << task
+ end
- def initialize (configuration)
- @result = configuration
- end
+ # method hook for default behaviour when an unknown property is met.
+ # Just ignore it and print a warning message.
+ def method_missing(name, *args)
+ WLog.warn("Property '#{name}' in config file is not defined, ignoring it...")
+ end
- # method hook for name property
- def war_file(*val)
- WLog.warn "property 'war_file' takes only one argument" if val.size > 1
- @result.war_file = val[0]
- end
-
- def exclude_files(*val)
- WLog.warn "property 'exclude_files' takes only one argument" if val.size > 1
- @result.exclude_files(val[0])
- end
-
- def servlet(*val)
- WLog.warn "property 'servlet' takes only one argument" if val.size > 1
- @result.servlet = val[0]
- end
-
- def compile_ruby(*val)
- WLog.warn "property 'compile_ruby' takes only one argument" if val.size > 1
- unless is_either_true_or_false?(val[0])
- WLog.warn "property 'compile_ruby' must be either true or false"
- return
- end
- @result.compile_ruby = val[0]
- end
-
- def add_gem_dependencies(*val)
- WLog.warn "property 'add_gem_dependencies' takes only one argument" if val.size > 1
- unless is_either_true_or_false?(val[0])
- WLog.warn "property 'add_gem_dependencies' must be either true or false"
- return
- end
- @result.add_gem_dependencies = val[0]
- end
-
- def keep_source(*val)
- WLog.warn "property 'keep_source' takes only one argument" if val.size > 1
- unless is_either_true_or_false?(val[0])
- WLog.warn "property 'keep_source' must be either true or false"
- return
- end
- @result.keep_source = val[0]
- end
-
- def add_file(name, config={})
- @result.add_file(name, config)
- end
-
- def add_gem(*val)
- WLog.warn "add_gem takes at most two arguments" if val.size > 2
- @result.add_gem(val[0], val[1])
- end
-
- def datasource_jndi(*val)
- WLog.warn "property 'datasource_jndi' takes only one argument" if val.size > 1
- unless is_either_true_or_false?(val[0])
- WLog.warn "property 'datasource_jndi' must be either true or false"
- return
- end
- @result.datasource_jndi = val[0]
- end
-
- def datasource_jndi_name(*val)
- WLog.warn "datasource_jndi_name takes at most one argument" if val.size > 1
- @result.datasource_jndi_name = val[0]
- end
-
- def staging(*val)
- puts "Warning: staging takes only one argument" if val.size > 1
- @result.staging = val[0]
- end
-
- # method hook for library property
- def include_library(name, properties)
- if properties == nil or properties[:version] == nil or properties[:locations] == nil
- WLog.warn "in include_library #{name}, 'version' and 'locations' specifications are mandatory"
- return
- end
- begin
- @result.add_java_library(@result.java_library(name, properties[:version], properties[:locations]))
- rescue
- WLog.warn "couldn't load library #{name}, check library definition in the config file"
- end
- end
-
- # method hook for maven library property
- def maven_library(group, name, version)
- begin
- @result.add_library(@result.maven_library(group, name, version))
- rescue
- WLog.warn "couldn't load maven library #{name}, check library definition in the config file"
- end
- end
-
- # method hook for default behaviour when an unknown property
- # is met in the dsl. By now, just ignore it and print a warning
- # message
- def method_missing(name, *args)
- WLog.warn "property '#{name}' in config file not defined, ignoring it ..."
- end
-
- # main parsing method. pass the file name for the dsl and the configuration
- # reference to evaluate against.
- def self.evaluate(filename, configuration)
- raise "file #{filename} not found " unless File.exists?(filename)
- dsl = new(configuration)
- dsl.instance_eval(File.read(filename) , filename)
- dsl
- end
-
- # utility
- def is_either_true_or_false?(obj)
- obj.class == TrueClass or obj.class == FalseClass
- end
- end #class DSL
-
end #class
end #module