Class: AppEngine::Rake::AppEngineTask

Inherits:
Rake::Task
  • Object
show all
Defined in:
lib/mirah/appengine_tasks.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ AppEngineTask

Returns a new instance of AppEngineTask.



33
34
35
36
# File 'lib/mirah/appengine_tasks.rb', line 33

def initialize(*args, &block)
  super
  AppEngineTask.tasks << self
end

Instance Method Details

#api_jarObject



136
137
138
# File 'lib/mirah/appengine_tasks.rb', line 136

def api_jar
  File.join(webinf_lib, File.basename(APIS))
end

#app_yamlObject



124
125
126
# File 'lib/mirah/appengine_tasks.rb', line 124

def app_yaml
  @war + '/WEB-INF/app.yaml'
end

#app_yaml_timestampObject



118
119
120
121
122
# File 'lib/mirah/appengine_tasks.rb', line 118

def app_yaml_timestamp
  if File.exist?(app_yaml)
    File.mtime(app_yaml)
  end
end

#check_for_updatesObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mirah/appengine_tasks.rb', line 81

def check_for_updates
  @update_thread = Thread.new do
    # Give the server time to start
    next_time = Time.now + 5
    until @done
      sleep_time = next_time - Time.now
      sleep(sleep_time) if sleep_time > 0
      next_time = Time.now + 1
      update
    end
  end
end

#init(src, war) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mirah/appengine_tasks.rb', line 38

def init(src, war)
  @src = src
  @war = war
  unless $CLASSPATH.include?(webinf_classes)
    $CLASSPATH << webinf_classes
  end
  webinf_lib_jars.each do |jar|
    $CLASSPATH << jar unless $CLASSPATH.include?(jar)
  end
  Mirah.source_paths << src
  Mirah.dest_paths << webinf_classes
  directory(webinf_classes)
  directory(webinf_lib)

  file_create api_jar => webinf_lib do
    puts 'Coping apis'
    cp APIS, api_jar
  end

  task :server => [name] do
    check_for_updates
    args = [
      'java', '-cp', TOOLS,
      'com.google.appengine.tools.KickStart',
      'com.google.appengine.tools.development.DevAppServerMain',
      @war
    ]
    system *args
    @done = true
    @update_thread.join
  end
  task :upload => [name] do
    Java::ComGoogleAppengineTools::AppCfg.main(
        ['update', @war].to_java(:string))
  end

  enhance([api_jar])
end

#real_prerequisitesObject



77
78
79
# File 'lib/mirah/appengine_tasks.rb', line 77

def real_prerequisites
  prerequisites.map {|n| application[n, scope]}
end

#updateObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mirah/appengine_tasks.rb', line 94

def update
  begin
    timestamp = app_yaml_timestamp
    @last_app_yaml_timestamp ||= timestamp
    updated = false
    real_prerequisites.each do |dep|
      if dep.needed?
        puts "Executing #{dep.name}"
        dep.execute
        updated = true
      end
    end
    if updated || (timestamp != @last_app_yaml_timestamp)
      begin
        open('http://localhost:8080/_ah/reloadwebapp')
        @last_app_yaml_timestamp = timestamp
      rescue OpenURI::HTTPError
      end
    end
  rescue Exception
    puts $!, $@
  end
end

#webinf_classesObject



128
129
130
# File 'lib/mirah/appengine_tasks.rb', line 128

def webinf_classes
  @war + '/WEB-INF/classes'
end

#webinf_libObject



132
133
134
# File 'lib/mirah/appengine_tasks.rb', line 132

def webinf_lib
  @war + '/WEB-INF/lib'
end

#webinf_lib_jarsObject



140
141
142
# File 'lib/mirah/appengine_tasks.rb', line 140

def webinf_lib_jars
  Dir.glob(webinf_lib + '/*.jar')
end