| LEFT | RIGHT |
|---|---|
| 1 #!/usr/bin/ruby1.8 -w | 1 #!/usr/bin/ruby1.8 -w |
| 2 # | 2 # |
| 3 # Copyright:: Copyright 2009 Google Inc. | 3 # Copyright:: Copyright 2009 Google Inc. |
| 4 # Original Author:: Ryan Brown (mailto:ribrdb@google.com) | 4 # Original Author:: Ryan Brown (mailto:ribrdb@google.com) |
| 5 # | 5 # |
| 6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
| 8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
| 9 # | 9 # |
| 10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 # | 11 # |
| 12 # Unless required by applicable law or agreed to in writing, software | 12 # Unless required by applicable law or agreed to in writing, software |
| 13 # distributed under the License is distributed on an "AS IS" BASIS, | 13 # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 # See the License for the specific language governing permissions and | 15 # See the License for the specific language governing permissions and |
| 16 # limitations under the License. | 16 # limitations under the License. |
| 17 | 17 |
| 18 require 'rexml/document' | 18 require 'rexml/document' |
| 19 require 'rexml/formatters/pretty' | 19 require 'rexml/formatters/pretty' |
|
woodie
2009/07/03 00:59:21
not used here anymore
| |
| 20 | 20 |
| 21 module AppEngine | 21 module AppEngine |
| 22 module Rack | 22 module Rack |
| 23 class Resources | 23 class Resources |
| 24 def initialize | 24 def initialize |
| 25 @includes = [] | 25 @includes = [] |
| 26 @excludes = [] | 26 @excludes = [] |
| 27 end | 27 end |
| 28 | 28 |
| 29 def include(glob) | 29 def include(glob) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 env = REXML::Element.new('env-variables') | 65 env = REXML::Element.new('env-variables') |
| 66 each do |name, value| | 66 each do |name, value| |
| 67 env.add_element('env-var'). | 67 env.add_element('env-var'). |
| 68 add_attributes( { "name" => name, "value" => value } ) | 68 add_attributes( { "name" => name, "value" => value } ) |
| 69 end | 69 end |
| 70 xml.add_element(env) | 70 xml.add_element(env) |
| 71 end | 71 end |
| 72 end | 72 end |
| 73 end | 73 end |
| 74 | 74 |
| 75 class RackApplication | 75 class RackApplication |
|
woodie
2009/07/03 02:39:57
# I liked my force-to-string mod, but with your wa
| |
| 76 attr_accessor :application, :version | 76 attr_accessor :application, :version |
| 77 attr_writer :ssl_enabled, :sessions_enabled | 77 attr_writer :ssl_enabled, :sessions_enabled |
| 78 attr_reader :system_properties, :environment_variables | 78 attr_reader :system_properties, :environment_variables |
| 79 attr_reader :static_files, :resource_files | 79 attr_reader :static_files, :resource_files |
| 80 | 80 |
| 81 def initialize | 81 def initialize |
| 82 @version = '1' | 82 @version = '1' |
| 83 @system_properties = PropertyMap[ 'os.arch' => '', | 83 @system_properties = PropertyMap[ 'os.arch' => '', |
| 84 'jruby.management.enabled' => 'false' ] | 84 'jruby.management.enabled' => 'false' ] |
| 85 @environment_variables = EnvVarMap.new | 85 @environment_variables = EnvVarMap.new |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 99 @version = version.to_s | 99 @version = version.to_s |
| 100 end | 100 end |
| 101 | 101 |
| 102 def configure(options={}) | 102 def configure(options={}) |
| 103 [:system_properties, :environment_variables].each do |key| | 103 [:system_properties, :environment_variables].each do |key| |
| 104 self.send(key).merge!(options.delete(key)) if options[key] | 104 self.send(key).merge!(options.delete(key)) if options[key] |
| 105 end | 105 end |
| 106 options.each { |k,v| self.send("#{k}=", v) } | 106 options.each { |k,v| self.send("#{k}=", v) } |
| 107 end | 107 end |
| 108 | 108 |
| 109 def to_xml | 109 def to_xml |
|
woodie
2009/07/03 00:59:21
It may be more appropriate to use doc
doc = REXML
| |
| 110 xml = REXML::Document.new.add_element('appengine-web-app') | 110 xml = REXML::Document.new.add_element('appengine-web-app') |
| 111 xml.add_attribute('xmlns','http://appengine.google.com/ns/1.0') | 111 xml.add_attribute('xmlns','http://appengine.google.com/ns/1.0') |
| 112 xml.add_element('application').add_text(application) | 112 xml.add_element('application').add_text(application) |
| 113 xml.add_element('version').add_text(version) | 113 xml.add_element('version').add_text(version) |
| 114 xml.add_element('public-root').add_text('/public') | 114 xml.add_element('public-root').add_text('/public') |
| 115 static_files.to_xml(xml, 'static-files') | 115 static_files.to_xml(xml, 'static-files') |
| 116 resource_files.to_xml(xml, 'resource-files') | 116 resource_files.to_xml(xml, 'resource-files') |
| 117 system_properties.to_xml(xml) | 117 system_properties.to_xml(xml) |
| 118 environment_variables.to_xml(xml) | 118 environment_variables.to_xml(xml) |
| 119 xml.add_element('sessions-enabled'). | 119 if sessions_enabled? |
| 120 add_text('true') if sessions_enabled? | 120 xml.add_element('sessions-enabled').add_text('true') |
| 121 xml.add_element('ssl-enabled'). | |
| 122 add_text('true') if ssl_enabled? | |
| 123 xml | |
| 124 end | |
| 125 | |
| 126 def write | |
| 127 Dir.mkdir('WEB-INF') unless File.exists?('WEB-INF') | |
| 128 open('WEB-INF/appengine-web.xml', 'w') do |out| | |
| 129 pretty_xml(out) | |
| 130 end | 121 end |
| 131 end | 122 if ssl_enabled? |
| 132 | 123 xml.add_element('ssl-enabled').add_text('true') |
| 133 def pretty_xml(out=nil) | 124 end |
| 134 fmt = REXML::Formatters::Pretty.new | 125 return xml |
| 135 fmt.compact = true | |
| 136 fmt.write(to_xml, out || String.new) | |
| 137 end | 126 end |
| 138 end | 127 end |
| 139 | 128 |
| 140 class << self | 129 class << self |
| 141 def app | 130 def app |
| 142 @app ||= RackApplication.new | 131 @app ||= RackApplication.new |
| 143 end | 132 end |
| 144 | 133 |
| 145 def configure(options={}) | 134 def configure(options={}) |
| 146 self.app.configure(options) | 135 self.app.configure(options) |
| 147 end | 136 end |
| 148 | 137 |
| 149 def environment | 138 def environment |
| 150 if $servlet_context | 139 if $servlet_context |
| 151 if $servlet_context.server_info =~ %r{^Google App Engine Development/} | 140 if $servlet_context.server_info =~ %r{^Google App Engine Development/} |
| 152 "development" | 141 "development" |
| 153 elsif $servlet_context.server_info =~ %r{^Google App Engine/} | 142 elsif $servlet_context.server_info =~ %r{^Google App Engine/} |
| 154 "production" | 143 "production" |
| 155 end | 144 end |
| 156 end | 145 end |
| 157 end | 146 end |
| 158 end | 147 end |
| 159 end | 148 end |
| 160 end | 149 end |
| 161 | 150 |
| LEFT | RIGHT |