Class: AppEngine::Admin::JRubyAppCfg

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

Constant Summary collapse

NO_XML_COMMANDS =
%w{version}
RUBY_COMMANDS =
%w{gem bundle help run generate_app}
COMMAND_SUMMARY =
<<EOF
  run: run jruby in your application environment.
  bundle: package your application for deployment.
  The 'run' command assumes the app directory is the current directory.
EOF

Class Method Summary collapse

Class Method Details

.appcfg_commandObject



126
127
128
129
130
131
# File 'lib/appengine-tools/appcfg.rb', line 126

def appcfg_command
  plugin_jar = File.join(File.dirname(__FILE__), 'app_yaml.jar')
  command = %W(java -cp #{AppEngine::SDK::TOOLS_JAR})
  command << "-Dcom.google.appengine.plugin.path=#{plugin_jar}"
  command << 'com.google.appengine.tools.admin.AppCfg'
end

.bundle(*args) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/appengine-tools/appcfg.rb', line 76

def bundle(*args)
  if File.directory?(args[-1] || '')
    AppEngine::Admin.bundle_app(*args)
  else
    bundle_help
  end
end

.bundle_helpObject



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/appengine-tools/appcfg.rb', line 84

def bundle_help
  help = <<EOF
#{$0} bundle [gem bundle options] app_dir

Bundles the gems listed in Gemfile and generates files necessary
to run an application as a servlet. This runs automatically for you,
but you need to run it manually to update gems if you don't specify
a version number. Pass --update to refresh bundled gems.

EOF
end

.gem(*args) ⇒ Object



96
97
98
# File 'lib/appengine-tools/appcfg.rb', line 96

def gem(*args)
  gem_help
end

.gem_helpObject



100
101
102
103
104
105
106
107
108
# File 'lib/appengine-tools/appcfg.rb', line 100

def gem_help
  help = <<EOF

Sorry, the 'appcfg.rb gem' option is deprecated.
Simply update the 'Gemfile' and run 'appcfg.rb bundle .' instead.

EOF
  puts help
end

.generate_app(*args) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/appengine-tools/appcfg.rb', line 54

def generate_app(*args)
  if args and args.size > 0
    appdir = args.pop
    webinf = File.join(appdir, 'WEB-INF')
    FileUtils.mkdir_p(webinf)
    AppEngine::Admin.bundle_app(appdir)
  else
    generate_app_help
  end
end

.generate_app_helpObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/appengine-tools/appcfg.rb', line 65

def generate_app_help
  help = <<EOF
#{$0} generate_app app_dir

Generates a sample Rack application in app_dir.
The directory is created if it doesn't exist.

EOF
  puts help
end

.help(command = nil) ⇒ Object



133
134
135
136
137
138
139
140
141
142
# File 'lib/appengine-tools/appcfg.rb', line 133

def help(command=nil)
  puts
  if command != 'help' && RUBY_COMMANDS.include?(command)
    puts send("#{command}_help")
  else
    java_args = appcfg_command << 'help'
    java_args << command if command
    print_help(%x{#{java_args.map{|x| x.inspect}.join(' ')}}, !command)
  end
end

.main(args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/appengine-tools/appcfg.rb', line 34

def main(args)
  command, parsed_args = parse_args(args)
  if RUBY_COMMANDS.include? command
    send(command, *parsed_args)
    return
  end
  if command && !NO_XML_COMMANDS.include?(command)
    path = parsed_args[0]
    AppEngine::Admin.bundle_app(path)
    updater = AppEngine::Admin::UpdateCheck.new(path)
    updater.nag
  end
  puts "=> Running AppCfg"
  run_appcfg(args)
end

.parse_args(args) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/appengine-tools/appcfg.rb', line 157

def parse_args(args)
  if RUBY_COMMANDS.include?(args[0])
    return [args[0], args[1, args.length]]
  elsif args.empty? || !(%w(-h --help) & args).empty?
    return ['help', []]
  elsif args[-3] == 'request_logs'
    command = args[-3]
    path = args[-2]
  else
    command = args[-2]
    path = args[-1]
  end
  return [command, [path]]
end


144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/appengine-tools/appcfg.rb', line 144

def print_help(help, summary)
  help.gsub!('AppCfg', $0)
  count = 0
  help.each_line do |line|
    line.chomp!
    if summary && line.size > 0 && line.lstrip == line
      count += 1
      print COMMAND_SUMMARY if count == 3
    end
    puts line
  end
end

.run(*args) ⇒ Object



110
111
112
113
# File 'lib/appengine-tools/appcfg.rb', line 110

def run(*args)
  AppEngine::Admin.bundle_deps('.')
  AppEngine::Development.boot_app('.', args)
end

.run_appcfg(args) ⇒ Object



50
51
52
# File 'lib/appengine-tools/appcfg.rb', line 50

def run_appcfg(args)
  exec *(appcfg_command + args)
end

.run_helpObject



115
116
117
118
119
120
121
122
123
124
# File 'lib/appengine-tools/appcfg.rb', line 115

def run_help
  help = <<EOF
#{$0} run [ruby args]

Starts the jruby interpreter within your application's environment.
Use `#{$0} run -S command` to run a command such as rake or irb.
Must be run from the application directory, after running bundle.

EOF
end