tccbuilder 0.2.5 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.3.1
@@ -3,6 +3,8 @@ class TCCBuilder
3
3
  require 'rexml/document'
4
4
  require 'tccbuilder/errors'
5
5
  require 'tccbuilder/cmdlet'
6
+ require 'tccbuilder/ext/string'
7
+ require 'tccbuilder/xml_elements'
6
8
 
7
9
  attr_reader :options
8
10
  attr_reader :version
@@ -19,25 +21,23 @@ class TCCBuilder
19
21
  else
20
22
  raise UnsupportedTomcatVersion, "Unsupported Tomcat version: #{@version}"
21
23
  end
22
- @server_xml = klass.new(@options.config_file)
24
+ @server_xml = klass.new(@options[:config_file])
23
25
  end
24
26
 
25
27
  def add_virtual_host
26
- raise VirtualHostAlreadyExists if self.server_xml.virtual_host_exists?(self.options.name, self.options.service)
27
- self.server_xml.add_virtual_host(self.options.name, self.options.service, self.options)
28
+ raise VirtualHostAlreadyExists if self.server_xml.virtual_host_exists?(self.options[:name], self.options[:service])
29
+ self.server_xml.add_virtual_host(self.options[:name], self.options[:service], self.options[:app_base], self.options)
28
30
  self.save
29
31
  end
30
32
 
31
33
  def rm_virtual_host
32
- raise VirtualHostNotFound unless self.server_xml.virtual_host_exists?(self.options.name, self.options.service)
33
- self.server_xml.remove_virtual_host(self.options.name, self.options.service)
34
+ raise VirtualHostNotFound unless self.server_xml.virtual_host_exists?(self.options[:name], self.options[:service])
35
+ self.server_xml.remove_virtual_host(self.options[:name], self.options[:service])
34
36
  self.save
35
37
  end
36
-
37
- def update_virtual_host
38
- # Stub
39
- # self.server_xml.update_virtual_host(self.options.name, self.options.service)
40
- # self.save
38
+
39
+ def virtual_host_exists
40
+ self.server_xml.virtual_host_exists?(self.options[:name], self.options[:service])
41
41
  end
42
42
 
43
43
  protected
@@ -6,36 +6,44 @@ class TCCBuilder
6
6
  def run!(bin_name, version, *arguments)
7
7
  @options = Options.new(bin_name, arguments)
8
8
 
9
- if @options.invalid_command
9
+ if @options[:invalid_command]
10
10
  em_puts "Invalid command: #{@options.invalid_command}"
11
- @options.show_help = true
11
+ @options[:show_help] = true
12
12
  end
13
13
 
14
- if @options.missing_options && !@options.invalid_command
15
- em_puts "Missing options: #{@options.missing_options.join(', ')}"
16
- @options.show_help = true
14
+ if @options[:missing_options] && !@options[:invalid_command]
15
+ em_puts "Missing options: #{@options[:missing_options].join(', ')}"
16
+ @options[:show_help] = true
17
17
  end
18
18
 
19
- if @options.invalid_option
20
- em_puts @options.invalid_option
21
- @options.show_help = true
19
+ if @options[:invalid_option]
20
+ em_puts @options[:invalid_option]
21
+ @options[:show_help] = true
22
22
  end
23
23
 
24
- if @options.show_help
25
- puts @options.opts
24
+ if @options[:show_help]
25
+ puts @options[:opts]
26
26
  Kernel.abort
27
27
  end
28
28
 
29
29
  tccbuilder = TCCBuilder.new(version, @options)
30
30
 
31
31
  begin
32
- case @options.command
32
+ case @options[:command]
33
33
  when "add_vhost"
34
34
  tccbuilder.add_virtual_host
35
- em_puts "VirtualHost successfully added! [#{@options.name}]"
35
+ em_puts "VirtualHost successfully added! [#{@options[:name]}]"
36
36
  when "rm_vhost"
37
37
  tccbuilder.rm_virtual_host
38
- em_puts "VirtualHost successfully deleted! [#{@options.name}]"
38
+ em_puts "VirtualHost successfully deleted! [#{@options[:name]}]"
39
+ when "vhost_exists"
40
+ if tccbuilder.virtual_host_exists
41
+ em_puts "VirtualHost exists. [#{@options[:name]}]"
42
+ exit 0
43
+ else
44
+ em_puts "VirtualHost does not exist. [#{@options[:name]}]"
45
+ exit 1
46
+ end
39
47
  end
40
48
  return 0
41
49
  rescue VirtualHostAlreadyExists
@@ -62,7 +70,7 @@ class TCCBuilder
62
70
  private
63
71
 
64
72
  def console_format(str)
65
- "[Tomcat Config Helper] #{str}"
73
+ "[tccbuilder] #{str}"
66
74
  end
67
75
  end
68
76
  end
@@ -0,0 +1,17 @@
1
+ class String
2
+ def camel_case
3
+ str = self.dup
4
+ str.camel_case!
5
+ end
6
+
7
+ def camel_case!
8
+ arr = self.split('_')
9
+ arr.first.downcase!
10
+ return arr.first unless arr.count > 1
11
+ marr = [arr.first]
12
+ marr << arr[1..arr.count].collect do |word|
13
+ word.capitalize!
14
+ end
15
+ marr.join('')
16
+ end
17
+ end
@@ -1,7 +1,7 @@
1
1
  require 'ostruct'
2
2
 
3
3
  class TCCBuilder
4
- class Options < OpenStruct
4
+ class Options < Hash
5
5
  require 'optparse'
6
6
 
7
7
  attr_reader :opts
@@ -15,10 +15,12 @@ class TCCBuilder
15
15
  super()
16
16
 
17
17
  # First argument should be a valid command or help_flag
18
- self.command = args.slice!(0)
18
+ self[:command] = args.slice!(0)
19
19
 
20
20
  # Setup default options
21
- self.service = "Catalina"
21
+ self[:service] = "Catalina"
22
+ self[:valves] = []
23
+ self[:aliases] = []
22
24
 
23
25
  @opts = OptionParser.new do |opt|
24
26
  opt.banner = "Usage: #{bin_name} [command] [options]"
@@ -31,65 +33,68 @@ class TCCBuilder
31
33
  opt.separator "Specific options:"
32
34
 
33
35
  opt.on("-c", "--config CONFIG", String, "Path to Tomcat server.xml config file.") do |f|
34
- self.config_file = f
36
+ self[:config_file] = f
35
37
  end
36
38
  opt.on("-n", "--hostname HOSTNAME", String, "Hostname of the target Virtual Host.") do |f|
37
- self.name = f
39
+ self[:name] = f
38
40
  end
39
41
  opt.on("-s", "--service [SERVICE]", String, "Service to place Virtual Host under. (Default: Catalina)") do |f|
40
- self.service = f
42
+ self[:service] = f
41
43
  end
42
44
  opt.on("-a", "--app-base APP_BASE", String, "Application base of Virtual Host.") do |f|
43
- self.app_base = f
45
+ self[:app_base] = f
44
46
  end
45
47
  opt.on("-p", "--path [PATH]", String, "Path of the Virtual Host's context.") do |f|
46
- self.path = f
48
+ self[:path] = f
47
49
  end
48
50
  opt.on("-d", "--doc-base [DOC_BASE]", String, "Document base of the Virtual Host's context.") do |f|
49
- self.doc_base = f
51
+ self[:doc_base] = f
50
52
  end
51
53
  opt.on("--debug-level [LEVEL]", Integer, "Debug level of Virtual Host's context.") do |f|
52
- self.debug = f
54
+ self[:debug] = f
53
55
  end
54
- opt.on("--aliases ALIAS_1,ALIAS_2", Array, "Optional list of aliases for Virtual Host.") do |list|
55
- self.aliases = list
56
+ opt.on("--aliases sharkvers.us,example.com", Array, "Optional list of aliases for Virtual Host.") do |list|
57
+ self[:aliases] = list
58
+ end
59
+ opt.on("--valve className=org.apache.catalina.valves.AccessLogValve,directory=logs,suffix=.log", Array, "Adds a valve element to the virtual host.") do |f|
60
+ self[:valves] << f
56
61
  end
57
62
  opt.on("-C", "--class-name [CLASS_NAME]", String, "Java class name of the implementation to use.") do |f|
58
- self.class_name = f
63
+ self[:class_name] = f
59
64
  end
60
65
  opt.on("--disable-unpack-wars", "Enable unpack wars.") do
61
- self.unpack_wars = false
66
+ self[:unpack_wars] = false
62
67
  end
63
68
  opt.on("--reloadable", "Enable reloadable flag.") do
64
- self.reloadable = true
69
+ self[:reloadable] = true
65
70
  end
66
71
  opt.on("--disable-auto-deploy", "Disables periodic checks for new or updated web applications while running.") do
67
- self.auto_deploy = false
72
+ self[:auto_deploy] = false
68
73
  end
69
74
  opt.on("--background-processor-delay", "Sets the delay in seconds between invocation of backgroundProcess method on host and child containers.") do |f|
70
- self.background_processor_delay = f
75
+ self[:background_processor_delay] = f
71
76
  end
72
77
  opt.on("--disable-deploy-on-startup", "Indicates if web applications from this host should be automatically deployed when Tomcat starts.") do
73
- self.deploy_on_startup = false
78
+ self[:deploy_on_startup] = false
74
79
  end
75
80
  opt.on_tail(HELP_FLAG, "--help", "Show this message.") do
76
- self.show_help = true
81
+ self[:show_help] = true
77
82
  end
78
83
  end
79
-
84
+
80
85
  begin
81
86
  @opts.parse!(args)
82
87
  rescue OptionParser::InvalidOption => e
83
- self.invalid_option = e
88
+ self[:invalid_option] = e
84
89
  end
85
90
 
86
- if self.command == HELP_FLAG
87
- self.show_help = true
91
+ if self[:command] == HELP_FLAG
92
+ self[:show_help] = true
88
93
  else
89
94
  mandatory_flags = [:config_file, :name]
90
- missing_required_opts = mandatory_flags.select { |param| self.send(param).nil? }
95
+ missing_required_opts = mandatory_flags.select { |param| !self.has_key?(param) }
91
96
  unless missing_required_opts.empty?
92
- self.missing_options = missing_required_opts
97
+ self[:missing_options] = missing_required_opts
93
98
  end
94
99
  end
95
100
  end
@@ -1,6 +1,5 @@
1
1
  class TCCBuilder
2
2
  module Tomcat6
3
- autoload :VirtualHost, 'tccbuilder/tomcat6/virtual_host'
4
- autoload :ServerXML, 'tccbuilder/tomcat6/server_xml'
3
+ autoload :ServerXML, 'tccbuilder/tomcat6/server_xml'
5
4
  end
6
5
  end
@@ -1,11 +1,11 @@
1
+ require 'rexml/document'
2
+
1
3
  class TCCBuilder
2
4
  module Tomcat6
3
5
  class ServerXML
4
- require 'ostruct'
5
- require 'rexml/document'
6
-
7
6
  attr_reader :xml
8
7
  attr_reader :file
8
+
9
9
  FORMATTER = REXML::Formatters::Pretty.new
10
10
 
11
11
  def initialize(file)
@@ -14,36 +14,33 @@ class TCCBuilder
14
14
  @xml = REXML::Document.new(raw, :raw => :all).root
15
15
  end
16
16
 
17
- def add_virtual_host(name, service, params)
18
- host = VirtualHost.new(name, service)
17
+ def add_virtual_host(name, service, app_base, options = {})
18
+ host = TCCBuilder::XMLElements::VirtualHost.new(name, service)
19
19
 
20
- # All implementations of Host support the following attribute:
21
- host.app_base = params.app_base if params.respond_to?(:app_base)
22
- host.auto_deploy = params.auto_deploy if params.respond_to?(:auto_deploy)
23
- host.background_processor_delay = params.background_processor_delay if params.respond_to?(:background_processor_delay)
24
- host.class_name = params.class_name if params.respond_to?(:class_name)
25
- host.deploy_on_startup = params.deploy_on_startup if params.respond_to?(:deploy_on_startup)
20
+ # All implementations of Host support the following attribute:
21
+ host.auto_deploy = options[:auto_deploy] if options.has_key?(:auto_deploy)
22
+ host.app_base = options[:app_base] if options.has_key?(:app_base)
23
+ host.background_processor_delay = options[:background_processor_delay] if options.has_key?(:background_processor_delay)
24
+ host.class_name = options[:class_name] if options.has_key?(:class_name)
25
+ host.deploy_on_startup = options[:deploy_on_startup] if options.has_key?(:deploy_on_startup)
26
26
  # The standard implementation of Host is org.apache.catalina.core.StandardHost. It supports the following additional attributes:
27
- host.unpack_wars = params.unpack_wars if params.respond_to?(:unpack_wars)
27
+ host.unpack_wars = options[:unpack_wars] if options.has_key?(:unpack_wars)
28
28
 
29
+ host.add_context
29
30
  # All implementations of Context support the following attributes:
30
- host.path = params.path || String.new
31
- host.doc_base = params.doc_base || String.new
32
- host.debug = params.debug if params.respond_to?(:debug)
33
- host.reloadable = params.reloadable if params.respond_to?(:reloadable)
34
-
35
- if params.aliases
36
- params.aliases.each do |al|
37
- host.add_alias(al)
38
- end
31
+ host.context.path = options[:path] || String.new
32
+ host.context.doc_base = options[:doc_base] || String.new
33
+ host.context.debug = options[:debug] if options.has_key?(:debug)
34
+ host.context.reloadable = options[:reloadable] if options.has_key?(:reloadable)
35
+
36
+ if options[:valves]
37
+ options[:valves].each { |valve| host.add_valve(valve) }
39
38
  end
40
-
41
- # TODO: Make valves configurable
42
- host.add_valve "org.apache.catalina.valves.AccessLogValve", :directory => "logs",
43
- :prefix => "#{name}_access_log.",
44
- :suffix => ".log",
45
- :pattern => "common"
46
-
39
+
40
+ if options[:aliases]
41
+ options[:aliases].each { |al| host.add_alias(al) }
42
+ end
43
+
47
44
  engine_element = get_engine_element(service)
48
45
  engine_element.add_element(host.to_rexml)
49
46
  end
@@ -52,10 +49,6 @@ class TCCBuilder
52
49
  @xml.delete_element("Service[@name='#{service}']/Engine/Host[@name='#{name}']")
53
50
  end
54
51
 
55
- def update_virtual_host(name, service, params)
56
- host = @xml.elements["Server[@name='#{service}']/Engine/Host[@name='#{name}']"]
57
- end
58
-
59
52
  def virtual_host_exists?(name, service)
60
53
  host = @xml.elements["Service[@name='#{service}']/Engine/Host[@name='#{name}']"]
61
54
  host.nil? ? false : true
@@ -0,0 +1,8 @@
1
+ class TCCBuilder
2
+ module XMLElements
3
+ autoload :Base, 'tccbuilder/xml_elements/base'
4
+ autoload :Context, 'tccbuilder/xml_elements/context'
5
+ autoload :Valve, 'tccbuilder/xml_elements/valve'
6
+ autoload :VirtualHost, 'tccbuilder/xml_elements/virtual_host'
7
+ end
8
+ end
@@ -0,0 +1,54 @@
1
+ require 'rexml/document'
2
+
3
+ class TCCBuilder
4
+ module XMLElements
5
+ class Base
6
+ attr_reader :attributes
7
+
8
+ def initialize(name, attributes = {})
9
+ @key_element = REXML::Element.new(name)
10
+ attributes.each do |k,v|
11
+ add_attribute(k, v)
12
+ end
13
+ end
14
+
15
+ def add_attribute(name, value)
16
+ @key_element.attributes[name.to_s.camel_case!] = value
17
+ end
18
+
19
+ def attributes
20
+ @key_element.attributes
21
+ end
22
+
23
+ def get_attribute(name)
24
+ @key_element.attributes[name.to_s.camel_case!]
25
+ end
26
+
27
+ def to_rexml
28
+ @key_element
29
+ end
30
+
31
+ def method_missing(method_sym, *args, &block)
32
+ method_str = method_sym.to_s
33
+ if method_str =~ /^(.+)\=$/
34
+ add_attribute($1, args.first)
35
+ elsif attrib = get_attribute(method_str)
36
+ attrib
37
+ else
38
+ super
39
+ end
40
+ end
41
+
42
+ def respond_to?(method_sym, include_private = false)
43
+ method_str = method_sym.to_s
44
+ if method_str =~ /^(.+)\=$/
45
+ true
46
+ elsif get_attribute(method_str)
47
+ true
48
+ else
49
+ super
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,9 @@
1
+ class TCCBuilder
2
+ module XMLElements
3
+ class Context < Base
4
+ def initialize(attributes = {})
5
+ super("Context", attributes)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class TCCBuilder
2
+ module XMLElements
3
+ class Valve < Base
4
+ attr_reader :class_name
5
+
6
+ def initialize(class_name, attributes = {})
7
+ super("Valve", attributes)
8
+ @class_name = class_name
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ class TCCBuilder
2
+ module XMLElements
3
+ class VirtualHost < Base
4
+ attr_reader :service
5
+
6
+ attr_reader :aliases
7
+ attr_reader :valves
8
+ attr_reader :context
9
+
10
+ def initialize(name, service, attributes = {})
11
+ super("Host", attributes)
12
+ @aliases = []
13
+ @valves = []
14
+ @context = nil
15
+ @service = service
16
+ self.name = name
17
+ end
18
+
19
+ def add_alias(text)
20
+ al = @key_element.add_element("Alias")
21
+ al.text = text
22
+ return al
23
+ end
24
+
25
+ def add_valve(class_name, options = {})
26
+ valve = Valve.new(class_name, options)
27
+ @key_element.add_element(valve.to_rexml)
28
+ @valves << valve
29
+ return valve
30
+ end
31
+
32
+ def add_context(options = {})
33
+ context = Context.new(options)
34
+ @key_element.add_element(context.to_rexml)
35
+ @context = context
36
+ end
37
+ end
38
+ end
39
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tccbuilder}
8
- s.version = "0.2.5"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jamie Winsor"]
12
- s.date = %q{2010-10-26}
12
+ s.date = %q{2010-11-10}
13
13
  s.default_executable = %q{tc6confbldr}
14
14
  s.description = %q{Utilities to assist in configuring Tomcat via Ruby or the command line}
15
15
  s.email = %q{resetexistence@gmail.com}
@@ -29,13 +29,20 @@ Gem::Specification.new do |s|
29
29
  "lib/tccbuilder.rb",
30
30
  "lib/tccbuilder/cmdlet.rb",
31
31
  "lib/tccbuilder/errors.rb",
32
+ "lib/tccbuilder/ext/string.rb",
32
33
  "lib/tccbuilder/options.rb",
33
34
  "lib/tccbuilder/tomcat6.rb",
34
35
  "lib/tccbuilder/tomcat6/server_xml.rb",
35
- "lib/tccbuilder/tomcat6/virtual_host.rb",
36
+ "lib/tccbuilder/xml_elements.rb",
37
+ "lib/tccbuilder/xml_elements/base.rb",
38
+ "lib/tccbuilder/xml_elements/context.rb",
39
+ "lib/tccbuilder/xml_elements/valve.rb",
40
+ "lib/tccbuilder/xml_elements/virtual_host.rb",
36
41
  "tccbuilder.gemspec",
37
42
  "test/helper.rb",
38
- "test/test_tccbuilder.rb"
43
+ "test/test_string_ext.rb",
44
+ "test/test_tccbuilder.rb",
45
+ "test/test_virtual_host.rb"
39
46
  ]
40
47
  s.homepage = %q{http://github.com/resetexistence/tccbuilder}
41
48
  s.rdoc_options = ["--charset=UTF-8"]
@@ -44,7 +51,9 @@ Gem::Specification.new do |s|
44
51
  s.summary = %q{Utilities to assist in configuring Tomcat via Ruby or the command line}
45
52
  s.test_files = [
46
53
  "test/helper.rb",
47
- "test/test_tccbuilder.rb"
54
+ "test/test_string_ext.rb",
55
+ "test/test_tccbuilder.rb",
56
+ "test/test_virtual_host.rb"
48
57
  ]
49
58
 
50
59
  if s.respond_to? :specification_version then
@@ -3,7 +3,11 @@ require 'test/unit'
3
3
 
4
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
- require 'tcchelper'
6
+ require 'tccbuilder'
7
+ require 'ruby-debug'
7
8
 
8
9
  class Test::Unit::TestCase
10
+ def new_sample_vhost
11
+ TCCBuilder::XMLElements::VirtualHost.new("example.com", "catalina", "web/apps")
12
+ end
9
13
  end
@@ -0,0 +1,15 @@
1
+ require 'helper'
2
+
3
+ class TestTCCBuilder < Test::Unit::TestCase
4
+ require 'tccbuilder/ext/string'
5
+
6
+ def test_camel_case_one_word_should_not_modify
7
+ one_word = "jamie"
8
+ assert_equal "jamie", one_word.camel_case!
9
+ end
10
+
11
+ def test_camel_case_two_words_should_modify
12
+ two_words = "jamie_winsor"
13
+ assert_equal "jamieWinsor", two_words.camel_case!
14
+ end
15
+ end
@@ -0,0 +1,91 @@
1
+ require 'helper'
2
+
3
+ class TestVirtualHost < Test::Unit::TestCase
4
+ require 'tccbuilder/tomcat6'
5
+
6
+ def test_attribute_auto_asignment
7
+ vhost_name = "example.com"
8
+ vhost = TCCBuilder::XMLElements::VirtualHost.new(vhost_name, "catalina", "web/apps")
9
+ assert_equal(vhost.name, vhost_name)
10
+ vhost.name = new_vhost_name = "example2.com"
11
+ assert_equal(vhost.name, new_vhost_name)
12
+ end
13
+
14
+ def test_setting_attributes_should_camel_case
15
+ vhost = new_sample_vhost
16
+ new_vhost_name = "sharkvers.us"
17
+ vhost.name = new_vhost_name
18
+ vhost.background_processor_delay = "true"
19
+ vhost.class_name = "org.apache.something"
20
+ assert vhost.attributes.has_key?('name')
21
+ assert vhost.attributes.has_key?('backgroundProcessorDelay')
22
+ assert vhost.attributes.has_key?('className')
23
+ assert !vhost.attributes.has_key?('background_processor_delay')
24
+ assert !vhost.attributes.has_key?('class_name')
25
+ end
26
+
27
+ def test_getting_attributes_should_respond_to_non_camel_case
28
+ vhost = new_sample_vhost
29
+ vhost.name = new_vhost_name = "sharkvers.us"
30
+ vhost.background_processor_delay = background_processor_delay = "true"
31
+ vhost.class_name = class_name = "org.apache.something"
32
+ assert_equal vhost.name, "sharkvers.us"
33
+ assert_equal vhost.background_processor_delay, background_processor_delay
34
+ assert_equal vhost.class_name, class_name
35
+ end
36
+
37
+ def test_adding_context
38
+ vhost = new_sample_vhost
39
+ assert_nil vhost.context
40
+ path = "/"
41
+ doc_base = "webapps/apps"
42
+ debug = "0"
43
+ reloadable = "true"
44
+ vhost.add_context :path => path,
45
+ :doc_base => doc_base,
46
+ :debug => debug,
47
+ :reloadable => reloadable
48
+
49
+ assert vhost.context
50
+ assert_equal vhost.context.path, path
51
+ assert_equal vhost.context.doc_base, doc_base
52
+ assert_equal vhost.context.debug, debug
53
+ assert_equal vhost.context.reloadable, reloadable
54
+ end
55
+
56
+ def test_adding_valves
57
+ vhost = new_sample_vhost
58
+ assert_equal 0, vhost.valves.length
59
+ class_name = "org.apache.catalina.valves.AccessLogValve"
60
+ directory = "logs"
61
+ prefix = "access_log."
62
+ suffix = ".log"
63
+ pattern = "common"
64
+ vhost.add_valve class_name,
65
+ :directory => directory,
66
+ :prefix => prefix,
67
+ :suffix => suffix,
68
+ :pattern => pattern
69
+ assert_equal 1, vhost.valves.count
70
+ assert_equal vhost.valves.first.directory, directory
71
+ assert_equal vhost.valves.first.prefix, prefix
72
+ assert_equal vhost.valves.first.suffix, suffix
73
+ assert_equal vhost.valves.first.pattern, pattern
74
+ end
75
+
76
+ def test_should_add_multiple_valves
77
+ vhost = new_sample_vhost
78
+ assert_equal 0, vhost.valves.length
79
+ vhost.add_valve "org.apache.catalina.valves.AccessLogValve",
80
+ :directory => "logs",
81
+ :prefix => "access_log.",
82
+ :suffix => ".log",
83
+ :pattern => "common"
84
+ vhost.add_valve "org.apache.catalina.valves.AccessLogValve",
85
+ :directory => "logs",
86
+ :prefix => "access_log.",
87
+ :suffix => ".log",
88
+ :pattern => "common"
89
+ assert_equal 2, vhost.valves.count
90
+ end
91
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tccbuilder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 5
10
- version: 0.2.5
8
+ - 3
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jamie Winsor
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-26 00:00:00 -07:00
18
+ date: 2010-11-10 00:00:00 -08:00
19
19
  default_executable: tc6confbldr
20
20
  dependencies: []
21
21
 
@@ -39,13 +39,20 @@ files:
39
39
  - lib/tccbuilder.rb
40
40
  - lib/tccbuilder/cmdlet.rb
41
41
  - lib/tccbuilder/errors.rb
42
+ - lib/tccbuilder/ext/string.rb
42
43
  - lib/tccbuilder/options.rb
43
44
  - lib/tccbuilder/tomcat6.rb
44
45
  - lib/tccbuilder/tomcat6/server_xml.rb
45
- - lib/tccbuilder/tomcat6/virtual_host.rb
46
+ - lib/tccbuilder/xml_elements.rb
47
+ - lib/tccbuilder/xml_elements/base.rb
48
+ - lib/tccbuilder/xml_elements/context.rb
49
+ - lib/tccbuilder/xml_elements/valve.rb
50
+ - lib/tccbuilder/xml_elements/virtual_host.rb
46
51
  - tccbuilder.gemspec
47
52
  - test/helper.rb
53
+ - test/test_string_ext.rb
48
54
  - test/test_tccbuilder.rb
55
+ - test/test_virtual_host.rb
49
56
  has_rdoc: true
50
57
  homepage: http://github.com/resetexistence/tccbuilder
51
58
  licenses: []
@@ -82,4 +89,6 @@ specification_version: 3
82
89
  summary: Utilities to assist in configuring Tomcat via Ruby or the command line
83
90
  test_files:
84
91
  - test/helper.rb
92
+ - test/test_string_ext.rb
85
93
  - test/test_tccbuilder.rb
94
+ - test/test_virtual_host.rb
@@ -1,111 +0,0 @@
1
- class TCCBuilder
2
- module Tomcat6
3
- class VirtualHost
4
- attr_reader :service
5
-
6
- attr_reader :app_base
7
- attr_reader :auto_deploy
8
- attr_reader :background_processor_delay
9
- attr_reader :class_name
10
- attr_reader :deploy_on_startup
11
- attr_reader :name
12
- attr_reader :unpack_wars
13
-
14
- attr_reader :path
15
- attr_reader :doc_base
16
- attr_reader :debug
17
- attr_reader :reloadable
18
-
19
- attr_reader :aliases
20
-
21
- def initialize(name, service)
22
- @host_element = REXML::Element.new("Host")
23
- @context_element = nil
24
- @service = service
25
- self.name = name
26
- end
27
-
28
- def app_base=(value)
29
- add_host_attribute("appBase", value)
30
- end
31
-
32
- def auto_deploy=(value)
33
- add_host_attribute("autoDeploy", value)
34
- end
35
-
36
- def background_processor_delay=(value)
37
- add_host_attribute("backgroundProcessorDelay", value)
38
- end
39
-
40
- def class_name=(value)
41
- add_host_attribute("className", value)
42
- end
43
-
44
- def deploy_on_startup=(value)
45
- add_host_attribute("deployOnStartup", value)
46
- end
47
-
48
- def name
49
- get_host_attribute("name")
50
- end
51
-
52
- def name=(value)
53
- add_host_attribute("name", value)
54
- end
55
-
56
- def unpack_wars=(value)
57
- add_host_attribute("unpackWars", value)
58
- end
59
-
60
- def path=(value)
61
- add_context_attribute("path", value)
62
- end
63
-
64
- def doc_base=(value)
65
- add_context_attribute("docBase", value)
66
- end
67
-
68
- def debug=(value)
69
- add_context_attribute("debug", value)
70
- end
71
-
72
- def reloadable=(value)
73
- add_context_attribute("reloadable", value)
74
- end
75
-
76
- def add_alias(text)
77
- al = @host_element.add_element("Alias")
78
- al.text = text
79
- return al
80
- end
81
-
82
- def add_valve(class_name, options = {})
83
- valve = @host_element.add_element("Valve")
84
- valve.attributes["className"] = class_name
85
- options.each do |key, value|
86
- valve.attributes[key.to_s] = value
87
- end
88
- return valve
89
- end
90
-
91
- def to_rexml
92
- @host_element
93
- end
94
-
95
- private
96
-
97
- def add_host_attribute(name, value)
98
- @host_element.attributes[name] = value
99
- end
100
-
101
- def get_host_attribute(name)
102
- @host_element.attributes[name]
103
- end
104
-
105
- def add_context_attribute(name, value)
106
- @context_element = @host_element.add_element("Context") if @context_element.nil?
107
- @context_element.attributes[name] = value
108
- end
109
- end
110
- end
111
- end