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.



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

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

Instance Method Details

#api_jarObject



138
139
140
# File 'lib/mirah/appengine_tasks.rb', line 138

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

#app_yamlObject



126
127
128
# File 'lib/mirah/appengine_tasks.rb', line 126

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

#app_yaml_timestampObject



120
121
122
123
124
# File 'lib/mirah/appengine_tasks.rb', line 120

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

#check_for_updatesObject



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

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



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
76
77
# File 'lib/mirah/appengine_tasks.rb', line 39

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
  Mirah.compiler_options = ['--classpath', Mirah::Env.encode_paths(CLASSPATH)]
  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



79
80
81
# File 'lib/mirah/appengine_tasks.rb', line 79

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

#updateObject



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

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



130
131
132
# File 'lib/mirah/appengine_tasks.rb', line 130

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

#webinf_libObject



134
135
136
# File 'lib/mirah/appengine_tasks.rb', line 134

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

#webinf_lib_jarsObject



142
143
144
# File 'lib/mirah/appengine_tasks.rb', line 142

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