Class: AppEngine::Admin::AppBundler

Inherits:
Object
  • Object
show all
Defined in:
lib/appengine-tools/bundler.rb

Constant Summary collapse

EXISTING_APIS =
/^appengine-api.*jar$/

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ AppBundler

Returns a new instance of AppBundler.



100
101
102
# File 'lib/appengine-tools/bundler.rb', line 100

def initialize(root_path)
  @app = Application.new(root_path)
end

Instance Method Details

#appObject



122
123
124
# File 'lib/appengine-tools/bundler.rb', line 122

def app
  @app
end

#bundle(args = []) ⇒ Object



104
105
106
107
108
109
# File 'lib/appengine-tools/bundler.rb', line 104

def bundle(args=[])
  bundle_deps(args)
  generate_config_ru
  generate_app_yaml
  create_public
end

#bundle_deps(args = []) ⇒ Object



111
112
113
114
115
# File 'lib/appengine-tools/bundler.rb', line 111

def bundle_deps(args=[])
  confirm_appdir
  create_webinf
  bundle_gems(args)
end

#bundle_gems(args) ⇒ Object



117
118
119
120
# File 'lib/appengine-tools/bundler.rb', line 117

def bundle_gems(args)
  gem_bundler = AppEngine::Admin::GemBundler.new(app.root)
  gem_bundler.bundle(args)
end

#confirm_appdirObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/appengine-tools/bundler.rb', line 126

def confirm_appdir
  if File.exists?(app.old_yaml)
    if File.exists?(app.app_yaml)
      puts ""
      puts "Warning, you have two versions of app.yaml."
      puts "We only use the version in the WEB-INF dir."
      puts ""
    else
      puts ""
      puts "Sorry, app.yaml needs to be inside the WEB-INF dir."
      puts "Don't worry, we are moving it there now."
      puts ""
      FileUtils.mv(app.old_yaml, app.app_yaml)
    end
  end
  unless File.exists?(app.app_yaml)or File.exists?(app.webinf)
    puts ""
    puts "Oops, this does not look like an application directory."
    puts "You need to create #{app.app_yaml}."
    puts ""
    puts "Run 'appcfg.rb generate_app #{app.path}'"
    puts "to generate a skeleton application."
    exit 1
  end
end

#create_publicObject



158
159
160
161
162
163
164
# File 'lib/appengine-tools/bundler.rb', line 158

def create_public
  if app.public_root and !File.exists?(app.public_root)
    Dir.mkdir(app.public_root)
  end
  FileUtils.touch(app.favicon_ico) unless File.exists?(app.favicon_ico)
  FileUtils.touch(app.robots_txt) unless File.exists?(app.robots_txt)
end

#create_webinfObject



152
153
154
155
156
# File 'lib/appengine-tools/bundler.rb', line 152

def create_webinf
  Dir.mkdir(app.webinf) unless File.exists?(app.webinf)
  Dir.mkdir(app.webinf_lib) unless File.exists?(app.webinf_lib)
  Dir.mkdir(app.generation_dir) unless File.exists?(app.generation_dir)
end

#generate_app_yamlObject



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/appengine-tools/bundler.rb', line 174

def generate_app_yaml
  unless File.exists?(app.app_yaml)
    puts "=> Generating app.yaml"
    app_id = File.basename(File.expand_path(app.path)).
        downcase.gsub('_', '-').gsub(/[^-a-z0-9]/, '')
    stock_yaml = <<EOF
application: #{app_id}
version: 1
runtime: jruby
EOF
    File.open(app.app_yaml, 'w') {|f| f.write(stock_yaml)}
  end
end

#generate_config_ruObject



166
167
168
169
170
171
172
# File 'lib/appengine-tools/bundler.rb', line 166

def generate_config_ru
  unless File.exists?(app.config_ru)
    puts "=> Generating rackup"
    stock_rackup = "run lambda {Rack::Response.new('Hello').finish}\n"
    File.open(app.config_ru, 'w') {|f| f.write(stock_rackup) }
  end
end