Class: GeneratorTimeChecker

Inherits:
Object show all
Defined in:
lib/build/GeneratorTimeChecker.rb

Overview

TODO check generate api

Constant Summary collapse

@@latest_update_time =
nil
@@app_path =
nil
@@is_run_always =
false
@@cached_time =
nil
@@do_cache =
false

Instance Method Summary collapse

Instance Method Details

#check(xmlpath) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/build/GeneratorTimeChecker.rb', line 84

def check(xmlpath)
  #@@do_cache = false
  generate_xml = false
  
  extpath  = File.dirname(xmlpath)
  xml_time = File.mtime(File.new(xmlpath))
  
  #puts "xmlpath: #{xmlpath}; xml_time : #{xml_time}"
  # for generate in first time
  if @@is_run_always
    @@do_cache = true
    generate_xml = true
  elsif !(File.exist? File.join(extpath, "shared", "generated"))              ||
     !(File.exist? File.join(extpath, "platform", "android", "generated")) ||
     !(File.exist? File.join(extpath, "platform", "iphone", "generated"))  ||
#       !(File.exist? File.join(extpath, "platform", "osx", "generated"))     ||
#       !(File.exist? File.join(extpath, "platform", "wm", "generated"))      ||
#       !(File.exist? File.join(extpath, "platform", "wp8", "generated"))     ||
     !(File.exist? File.join(extpath, "..", "public", "api", "generated"))
    @@do_cache = true
    generate_xml = true
  elsif @@cached_time < xml_time
    puts "!!!"
    @@do_cache = true
    generate_xml = true
  end 
  
  generate_xml
end

#find_latest_modified_date(path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/build/GeneratorTimeChecker.rb', line 13

def find_latest_modified_date(path)
  #puts 'find_latest_modified_date.path=' + path.to_s
  
  latest_mod_time = nil      
  templates_dir   = Dir.new(path)
  
  templates_dir.each { |item|       
    if item == '.' || item == '..'
      next        
    end

    full_path = File.join(path, item)
    mod_time  = nil
    
    if File.directory?(full_path)
      mod_time = find_latest_modified_date(full_path)
      
      if mod_time.nil?
        next
      end            
    else
      mod_time = File.mtime(full_path)
    end
    
    if latest_mod_time.nil?
      latest_mod_time = mod_time
    else
      if latest_mod_time < mod_time
        latest_mod_time = mod_time
      end
    end
  }
  
  return latest_mod_time
end

#init(startdir, app_path) ⇒ Object



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
78
79
80
81
82
# File 'lib/build/GeneratorTimeChecker.rb', line 49

def init(startdir, app_path)
  @@app_path       = app_path
  templates_path   = File.join(startdir, "res", "generators", "templates", "api")
  rhogen_path      = File.join(startdir, "res", "generators", "rhogen.rb")
  
  api_time         = find_latest_modified_date(templates_path)
  rhogen_time      = File.mtime(rhogen_path)
  last_update_time = nil
  
  last_change_data = find_latest_modified_date(templates_path)
  time_cache_path  = File.join(@@app_path, "bin", "tmp", "rhogen.time")
   
  if last_change_data.nil?
    @@is_run_always = true
  end
  
  if File.exist? time_cache_path
    time_cache_file = File.new(time_cache_path)
    @@cached_time   = Time.parse(time_cache_file.gets)
    time_cache_file.close
    
    @@latest_update_time = rhogen_time >= api_time ? rhogen_time : api_time    
    puts 'latest_update_time=' + @@latest_update_time.to_s
    puts "cached_time : #{@@cached_time}"
          
    if @@cached_time < @@latest_update_time
      @@is_run_always = true
    end       
  else
    @@is_run_always = true
  end
  
  @@do_cache = false
end

#updateObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/build/GeneratorTimeChecker.rb', line 114

def update()
  if @@do_cache == false
    #puts "@@do_cache is FALSE"
    return
  end
  
  time_cache_path  = File.join(@@app_path, "bin", "tmp", "rhogen.time")

  FileUtils.mkdir(File.join(@@app_path, "bin") ) unless File.exist? File.join(@@app_path, "bin")
  FileUtils.mkdir(File.join(@@app_path, "bin", "tmp") ) unless File.exist? File.join(@@app_path, "bin", "tmp")
  
  time_cache_file = File.new(time_cache_path, "w+")
  time_cache_file.puts Time.new
  time_cache_file.close()
end