Class: Jake

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

Overview

Class with around building things

Constant Summary collapse

@@logger =
nil

Class Method Summary collapse

Class Method Details

.ant(dir, target) ⇒ Object



848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
# File 'lib/build/jake.rb', line 848

def self.ant(dir,target)

  srcdir = $config["build"]["srcdir"]
  rubypath = $config["build"]["rubypath"]
  excludelib = $config["build"]["excludelib"]
  excludeapps = $config["build"]["excludeapps"]
  compileERB = $config["build"]["compileERB"]


  args = []
  args << "-buildfile"
  args << dir + "/build.xml"
  args << '-Dsrc.dir=' + get_absolute(srcdir)
#    args << '-Druby.path=' + get_absolute(rubypath)
  args << '-Dexclude.lib=' + excludelib
  args << '-Dexclude.apps=' + excludeapps
  args << '-DcompileERB.path=' + get_absolute(compileERB)
  args << '-Dsrclib.dir=' + get_absolute(srcdir)


  args << target
  #puts args.to_s
  log Logger::INFO,run("ant.bat",args,dir)
end

.before_run_specObject



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/build/jake.rb', line 342

def self.before_run_spec()
  $total ||= 0
  $passed ||= 0
  $failed ||= 0
  $notsupported ||= 0
  $failed_lines ||= 0
  $passed_lines ||= 0
  $mspec_lines ||= 0
  $jasmine_lines ||= 0
  $total_lines_printed ||= 0
  $latest_test_line = ""
  $faillog = []
  @default_file_name = "junit.xml"
  $junitname = ''
  $junitlogs = {@default_file_name => []}
  $getdump = false
end

.build_file_map(dir, file_name, in_memory = false) ⇒ Object



969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
# File 'lib/build/jake.rb', line 969

def self.build_file_map(dir, file_name, in_memory = false)
  require 'digest/md5'

  psize    = dir.size + 1
  file_map = Array.new
  file_map_name = File.join(dir, file_name)
  dat      = nil

  if in_memory == false
    dat = File.open(file_map_name, 'w')
  end

  Dir.glob(File.join(dir, '**/*')).sort.each do |f|
    relpath = f[psize..-1]

    if File.directory?(f)
      type = 'dir'
    elsif File.file?(f)
      type = 'file'
    else
      next
    end

    if File.basename(f) == file_name
      next
    end

    md5 = (type == 'file' ? (Digest::MD5.file(f)).to_s : '')
    size    = File.stat(f).size
    tm      = File.stat(f).mtime.to_i

    if in_memory == true
      map_item = { :path => relpath, :size => size, :time => tm, :hash => md5}
      file_map << map_item
    else
      dat.puts "#{relpath}|#{type}|#{size.to_s}|#{tm.to_s}|#{md5}"
    end
  end

  if in_memory == false
    dat.close
  end

  return file_map
end

.clean_vsprops(file) ⇒ Object



695
696
697
698
699
700
701
702
703
704
705
# File 'lib/build/jake.rb', line 695

def self.clean_vsprops(file)
  changed = false
  edit_xml(file) do |doc|
    ['RHO_ROOT', 'TEMP_FILES_DIR'].each do |var|
      REXML::XPath.each(doc, "//UserMacro[@Name='#{var}']") do |node|
        changed = true
        node.remove
      end
    end
  end
end

.config(configfile) ⇒ Object



179
180
181
182
183
184
185
# File 'lib/build/jake.rb', line 179

def self.config(configfile)
  require 'yaml'

  conf = YAML::load(configfile)
  res = self.config_parse(conf)
  res
end

.config_parse(conf) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/build/jake.rb', line 221

def self.config_parse(conf)
  if conf.is_a?(Array)
    conf.collect! do |x|
      if x.is_a?(Hash) or x.is_a?(Array)
        x = config_parse(x)
        x
      else
        if x =~ /%(.*?)%/
          x.gsub!(/%.*?%/, conf.fetch_r($1).to_s)
        end
        s = x.to_s
        if File.exists? s
          s.gsub!(/\\/, '/')
	      end
	      s
      end
    end
  elsif conf.is_a?(Hash)
    newhash = Hash.new

    conf.each do |k,x|
      if x.is_a?(Hash) or x.is_a?(Array)
        newhash[k.to_s] = config_parse(x)
      else
        s = x.to_s
        if File.exists? s
          s.gsub!(/\\/, '/')
        end
        newhash[k.to_s] = s
      end
    end
    conf = newhash

    conf
  end

  conf
end

.copy_rhoconfig(source, target) ⇒ Object



1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
# File 'lib/build/jake.rb', line 1125

def self.copy_rhoconfig(source, target)
  override = get_config_override_params
  mentioned = Set.new

  lines = []

  # read file and edit overriden parameters
  File.open(source, 'r') do |file|
    while line = file.gets
      match = line.match(/^(\s*)(\w+)(\s*=\s*)/)
      if match
        name = match[2]
        if override.has_key?(name)
          lines << "#{match[1]}#{name}#{match[3]}#{override[name]}"
          mentioned << name
          next
        end
      end
      lines << line
    end
  end

  # append rest of overriden parameters to text
  override.each do |key, value|
    if !mentioned.include?(key)
      lines << ''
      lines << "#{key} = #{value}"
    end
  end

  # write text to target file
  File.open(target, 'w') do |file|
    lines.each { |l| file.puts l }
  end
end

.copyIfNeeded(src, dst) ⇒ Object



1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
# File 'lib/build/jake.rb', line 1310

def self.copyIfNeeded src, dst
  if File.directory? dst and !File.directory? src
    dst_path = File.join dst, File.basename(src)
  else
    dst_path = dst
  end
  unless File.exists? dst_path and FileUtils.identical? src, dst_path
    FileUtils.rm dst_path if File.exists? dst_path
    FileUtils.cp src, dst
  end
end

.decorate_specObject



333
334
335
336
337
338
339
340
# File 'lib/build/jake.rb', line 333

def self.decorate_spec
  $app_spec_decorator.before_spec unless $app_spec_decorator.nil?
  begin
    yield
  ensure
    $app_spec_decorator.after_spec unless $app_spec_decorator.nil?
  end
end

.edit_lines(file, out_file = nil) ⇒ Object



686
687
688
689
690
691
692
693
# File 'lib/build/jake.rb', line 686

def self.edit_lines(file, out_file = nil)
  out_file = file if out_file.nil?

  lines = File.readlines(file)
  File.open(out_file, 'w') do |f|
    lines.each { |line| f.puts(yield line) }
  end
end

.edit_xml(file, out_file = nil) {|doc| ... } ⇒ Object

Yields:



678
679
680
681
682
683
684
# File 'lib/build/jake.rb', line 678

def self.edit_xml(file, out_file = nil)
  out_file = file if out_file.nil?

  doc = REXML::Document.new(File.new(file).read)
  yield doc
  File.open(out_file, 'w') {|f| f << doc}
end

.edit_yml(file, out_file = nil) {|yml| ... } ⇒ Object

Yields:

  • (yml)


668
669
670
671
672
673
674
675
676
# File 'lib/build/jake.rb', line 668

def self.edit_yml(file, out_file = nil)
  out_file = file if out_file.nil?

  require 'yaml'

  yml = YAML::load_file(file)
  yield yml
  File.open(out_file, 'w') {|f| f.write yml.to_yaml}
end

.encrypt_files_by_AES(dir, key, extensions_list) ⇒ Object



890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
# File 'lib/build/jake.rb', line 890

def self.encrypt_files_by_AES(dir, key, extensions_list)

    puts "Jake.encrypt_files( dir:"+dir.to_s+", key:"+key.to_s+", ext_list:"+extensions_list.to_s+") BEGIN"
    if extensions_list == nil
        puts "extensions_list is NIL !"
        return
    end
    if !(extensions_list.is_a?(Array))
        puts "extensions_list is not Array !"+extensions_list.class.to_s
        return
    end

    psize    = dir.size + 1

    Dir.glob(File.join(dir, '**/*')).sort.each do |f|
      relpath = f[psize..-1]

      if File.directory?(f)
        type = 'dir'
      elsif File.file?(f)
        type = 'file'
      else
        next
      end

      #check file
      extension = File.extname(f).delete(".")
      if !extensions_list.include?(extension)
          next
      end

      #skip empty files
      next unless File.size?(f)

      next unless (File.basename(f) != "rhoconfig.txt")
      next unless (File.basename(f) != "rhofilelist.txt")
      next unless (File.basename(f) != "app_manifest.txt")

      puts "    encrypt file: "+f.to_s+" ..."

      #load file
      content = File.binread(f)
      #File.rename(f, f+".original")
      File.delete(f)



      #encrypt file
      #encrypted_content = public_key.public_encrypt( content )
      encrypted_content = AES.encrypt(content, key)


      #decrypted_content = AES.decrypt(encrypted_content, key)
      #File.open(f+".decrypted","wb") do |f|
      #    f.write(decrypted_content)
      #end

      #save file
      #output_f = File.new(f+".encrypted", "w")
      #output_f.puts encrypted_content
      #output_f.close

      File.open(f+".encrypted","wb") do |f|
          f.write(encrypted_content[0])
          f.write(encrypted_content[1])
	f.write(encrypted_content[2])
      end


      puts "        DONE"

    end
    puts "Jake.encrypt_files( dir:"+dir.to_s+", key:"+key.to_s+", ext_list:"+extensions_list.to_s+") END"

end

.enquote(str) ⇒ Object



1322
1323
1324
# File 'lib/build/jake.rb', line 1322

def self.enquote str
  "\"#{str}\""
end

.generate_AES_keyObject



886
887
888
# File 'lib/build/jake.rb', line 886

def self.generate_AES_key
    return AES.key
end

.get_absolute(path) ⇒ Object



196
197
198
# File 'lib/build/jake.rb', line 196

def self.get_absolute(path)
  get_absolute_ex(path, Dir.pwd())
end

.get_absolute_ex(path, currentdir) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/build/jake.rb', line 200

def self.get_absolute_ex(path, currentdir)
  ret_path = File.expand_path(path, currentdir)
  return ret_path  if File.exists?(ret_path)

  path = currentdir + "/" + path

  patharray = path.split(/\//)

  while idx = patharray.index("..") do
    if idx == 0
      raise "error getting absolute"
    end

    if patharray[idx-1] != ".."
      patharray.delete_at(idx)
      patharray.delete_at(idx-1)
    end
  end
  return patharray.join("/")
end

.get_config_override_paramsObject



1115
1116
1117
1118
1119
1120
1121
1122
1123
# File 'lib/build/jake.rb', line 1115

def self.get_config_override_params
  override = {}
  ENV.each do |key, value|
    key.match(/^rho_override_(.+)$/) do |match|
      override[match[1]] = value
    end
  end
  return override
end

.get_process_listObject



1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
# File 'lib/build/jake.rb', line 1224

def self.get_process_list
  cmd = nil
  args = nil
  proc_list = []

  if RUBY_PLATFORM =~ /(win|w)32$/
    cmd = 'WMIC'
    args = ['path', 'win32_process', 'get', 'Processid,Parentprocessid,Commandline']
  else
    cmd = 'ps'
    args = ['axww', '-o', 'pid', '-o', 'ppid', '-o', 'command']
  end

  output = run2 cmd, args, {:hide_output=>true}

  output.each_line do |line|
    #puts "[[#{line}]]"
    if RUBY_PLATFORM =~ /(win|w)32$/
      match_data = /^(.*)\s+(\d+)\s+(\d+)\s*$/.match line
      proc_list << {:pid=>match_data[3], :ppid=>match_data[2], :cmd=>match_data[1]} if match_data
    else
      match_data = /(\d+)\s+(\d+)\s+(.*)/.match line
      proc_list << {:pid=>match_data[1], :ppid=>match_data[2], :cmd=>match_data[3]} if match_data
    end
  end
  proc_list
end

.getBool(propObject, def_value = false) ⇒ Object



1265
1266
1267
1268
1269
1270
1271
1272
1273
# File 'lib/build/jake.rb', line 1265

def self.getBool(propObject, def_value=false)
  res = propObject

  return def_value unless res

  return true if res && (res.to_i() != 0 || res.casecmp("true") == 0 || res.casecmp("yes") == 0 )

  false
end

.getBuildBoolProp(propName, config_yml = $app_config, def_value = false) ⇒ Object



1275
1276
1277
1278
1279
1280
1281
1282
1283
# File 'lib/build/jake.rb', line 1275

def self.getBuildBoolProp(propName, config_yml=$app_config, def_value=false)
  res = getBuildProp(propName)

  return def_value unless res

  return true if res && (res.to_i() != 0 || res.casecmp("true") == 0 || res.casecmp("yes") == 0 )

  false
end

.getBuildBoolProp2(propName, propName2, config_yml = $app_config, def_value = false) ⇒ Object



1300
1301
1302
1303
1304
1305
1306
1307
1308
# File 'lib/build/jake.rb', line 1300

def self.getBuildBoolProp2(propName, propName2, config_yml=$app_config, def_value=false)
  res = getBuildProp2(propName, propName2)

  return def_value unless res

  return true if res && (res.to_i() != 0 || res.casecmp("true") == 0 || res.casecmp("yes") == 0 )

  false
end

.getBuildProp(propName, config_yml = $app_config) ⇒ Object



1256
1257
1258
1259
1260
1261
1262
1263
# File 'lib/build/jake.rb', line 1256

def self.getBuildProp(propName, config_yml=$app_config)
  res = nil

  res = config_yml[propName] if config_yml[propName]
  res = config_yml[$current_platform][propName] if config_yml[$current_platform] && config_yml[$current_platform][propName]

  res
end

.getBuildProp2(propName, propName2, config_yml = $app_config) ⇒ Object



1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
# File 'lib/build/jake.rb', line 1285

def self.getBuildProp2(propName, propName2, config_yml=$app_config)
  res = nil
  if config_yml[propName]
      res1 = config_yml[propName]
      res = res1[propName2] if res1 && res1[propName2]
  end

  if config_yml[$current_platform]
      res1 = config_yml[$current_platform][propName]
      res = res1[propName2] if res1 && res1[propName2]
  end

  res
end

.init_loggerObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/build/jake.rb', line 162

def self.init_logger
    if @@logger.nil?
        @@logger = Logger.new(STDOUT)
        $logger = @@logger
        if ENV["RHODES_BUILD_LOGGER_LEVEL"] and ENV["RHODES_BUILD_LOGGER_LEVEL"] != ""
            level = ENV["RHODES_BUILD_LOGGER_LEVEL"]
            if level == "DEBUG"
                @@logger.level = Logger::DEBUG
            end
            if level == "INFO"
                @@logger.level = Logger::INFO
            end
        end
    end
end

.jar(target, manifest, files, isfolder = false) ⇒ Object



753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/build/jake.rb', line 753

def self.jar(target,manifest,files,isfolder=false)
  jpath = $config["env"]["paths"]["java"]
  cmd = jpath && jpath.length()>0 ? File.join(jpath, "jar" ) : "jar"
  #cmd +=  ".exe" if RUBY_PLATFORM =~ /(win|w)32$/

  target.gsub!(/"/,"")

  args = []
  args << "cfm"
  args << target
  args << manifest
  if isfolder
    args << "-C"
    args << files
    args << "."
  else
    args << files
  end

  log Logger::DEBUG,run(cmd,args)


end

.jarfilelist(target) ⇒ Object



732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
# File 'lib/build/jake.rb', line 732

def self.jarfilelist(target)
  jpath = $config["env"]["paths"]["java"]
  cmd = jpath && jpath.length()>0 ? File.join(jpath, "jar" ) : "jar"

#    if RUBY_PLATFORM =~ /(win|w)32$/
#      cmd =  $config["env"]["paths"]["java"] + "/jar.exe"
#    else
#      cmd =  $config["env"]["paths"]["java"] + "/jar"
#    end
  target.gsub!(/"/,"")

  args = []
  args << "tf"
  args << target

  filelist = []
  run(cmd,args).each { |file| filelist << file if not file =~ /\/$/ }

  filelist
end

.localipObject



260
261
262
263
264
265
266
267
268
# File 'lib/build/jake.rb', line 260

def self.localip
  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true  # turn off reverse DNS resolution temporarily
  UDPSocket.open do |s|
    s.connect '174.142.8.58', 1
    s.addr.last
  end
ensure
  Socket.do_not_reverse_lookup = orig
end

.log(severity, message) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# File 'lib/build/jake.rb', line 151

def self.log( severity, message )
  if @@logger.nil?
      init_logger
  end
  if @@logger
    @@logger.log(severity, message)
  else
    puts message
  end
end

.make_rhoconfig_txtObject



1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
# File 'lib/build/jake.rb', line 1161

def self.make_rhoconfig_txt
  copy_rhoconfig(File.join($app_path, 'rhoconfig.txt'), File.join($srcdir, 'apps', 'rhoconfig.txt'))

  modify_rhoconfig_for_debug if $remote_debug

  app_version = "\r\napp_version='#{$app_config["version"]}'"
  app_version += "\r\napp_name='#{$app_config["name"]}'"
  app_version += "\r\ntitle_text='#{$app_config["name"]}'"  if $current_platform == "win32"
  app_version += "\r\norg_name='#{$app_config["vendor"]}'"  if $current_platform == "win32"
  app_version += "\r\nrho_app_id='#{$app_config["rho_app_id"]}'" if $app_config['rho_app_id']

  #store Rhodes version to rhoconfig
  version_path = File.join($startdir, 'version')
  version = ""
  File.open( version_path, 'rb' ){ |f| version = f.read() }
  app_version += "\r\nrhodes_gem_version='#{version.strip}'"

  if $is_webkit_engine == true
  File.open(File.join($srcdir,'apps/rhoconfig.txt'), "a"){ |f| f.write("\r\nwebengine=webkit") }
 end

  File.open(File.join($srcdir,'apps/rhoconfig.txt'), "a"){ |f| f.write(app_version) }
  File.open(File.join($srcdir,'apps/rhoconfig.txt.timestamp'), "w"){ |f| f.write(Time.now.to_f().to_s()) }
end

.modify_file_if_content_changed(file_name, f) ⇒ Object



873
874
875
876
877
878
879
880
881
882
883
884
# File 'lib/build/jake.rb', line 873

def self.modify_file_if_content_changed(file_name, f)
  f.rewind
  content = f.read()
  old_content = File.exists?(file_name) ? File.read(file_name) : ""

  if old_content != content
      log Logger::DEBUG, "!!!MODIFY #{file_name}"
      File.open(file_name, "w"){|file| file.write(content)}
  end

  f.close
end

.modify_rhoconfig_for_debugObject



1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 'lib/build/jake.rb', line 1102

def self.modify_rhoconfig_for_debug
  confpath_content = File.read($srcdir + "/apps/rhoconfig.txt") if File.exists?($srcdir + "/apps/rhoconfig.txt")
  log(Logger::INFO,"confpath_content=" + confpath_content.to_s)

  confpath_content += "\r\n" + "remotedebug=1"  if !confpath_content.include?("remotedebug=")
  confpath_content += "\r\n" + "debughosturl=" + $rhologhostaddr  if !confpath_content.include?("debughosturl=")

 #   puts "confpath_content=" + confpath_content.to_s
 #   puts  "$srcdir=" + $srcdir.to_s

  File.open($srcdir + "/apps/rhoconfig.txt", "w") { |f| f.write(confpath_content) }  if confpath_content && confpath_content.length()>0
end

.normalize_build_yml(yml = $app_config) ⇒ Object



187
188
189
190
# File 'lib/build/jake.rb', line 187

def self.normalize_build_yml(yml = $app_config)
  yml['wm'] = {} unless yml['wm'].is_a?(Hash)
  yml['wm']['webkit_outprocess'] = '0' if yml['wm']['webkit_outprocess'].nil?
end


360
361
362
363
364
365
366
367
# File 'lib/build/jake.rb', line 360

def self.print_statistic_in_progress
  dev = 10
  new_total = ($mspec_lines + $jasmine_lines) / dev
  if new_total*dev > $total_lines_printed
      $total_lines_printed = new_total*dev
      puts " "+$total_lines_printed.to_s+" tests / "+($passed_lines+$failed_lines).to_s+" checks prоcessed. Latest test is ["+$latest_test_line.to_s+"]"
  end
end

.process_spec_output(line) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/build/jake.rb', line 369

def self.process_spec_output(line)
    # Print MSpec example description
    log(Logger::INFO,line) if line =~ /\| - it/ or line =~ /\| describe/ or line =~ /\|   - /
    line = $1 if line =~ /^I\/APP\s+\(\s+[0-9]+\)\:\s+(.*)/
    if $getdump
      if line =~ /^I/
        $getdump = false
      else
        if !$faillog.include?(line)
          $faillog << line
        end
      end
    end

    if line =~ /JUNIT\| (.*)/          # JUNIT| XML
      $junitlogs[@default_file_name] << $1 if $junitlogs[@default_file_name] != nil
    elsif line =~ /JUNITNAME\|\s+(.*)/          # JUNITNAME| name
      $junitname = File.basename($1.strip,'.xml')
      $junitlogs[$junitname] = [] if $junitlogs[$junitname] != nil
    elsif line =~ /JUNITBLOB\| (.*)/
      if $junitname && $1
        $junitlogs[$junitname] << $1 if $junitlogs[$junitname] != nil
      end
    end

    ###
    # Here we are looking for the following pattern of spec stats:
    # ...   APP| ***Total:  ...
    # ...   APP| ***Passed: ...
    # ...   APP| ***Failed: ...
    # ...
    # ...   APP| ***Terminated
    # Bail out as soon as prev. line is found
    ###
    if line =~ /\| \*\*\*Total:\s+(.*)/  # | ***Total:
      $total += $1.to_i
    elsif line =~ /\| \*\*\*Passed:\s+(.*)/ # | ***Passed:
      $passed += $1.to_i
    elsif line =~ /\| \*\*\*Failed:\s+(.*)/    # | ***Failed:
      $failed += $1.to_i
    elsif line =~ /\| \*\*\*Not supported by Rhodes:\s+(.*)/    # | ***Failed:
      $notsupported += $1.to_i
    elsif line =~ /\| \*\*\*Terminated\s+(.*)/ # | ***Terminated
      return false
    end
    #passed Jasmine
    #Jasmine specRunner| <ORM Db Reset specs> : VT302-0054 | should delete all records only from selected models propertyBag databaseFullResetEx : Passed.
    if line =~ /I.* Jasmine specRunner\| .*Passed\./
      $passed_lines = $passed_lines +1
    end

    #Jasmine test lines
    #Jasmine specRunner| <ORM Db Reset specs> : VT302-0054 | should delete all records only from selected models propertyBag databaseFullResetEx started
    if line =~ /I.* Jasmine specRunner\| (.*) started/
      $jasmine_lines = $jasmine_lines +1
      $latest_test_line = $1.chomp
    end

    # tests for MSpec
    if line =~ /\| MSPEC run spec: \[(.*)\]/
      $mspec_lines = $mspec_lines +1
      $latest_test_line = $1.chomp
    end
    # Passed for MSpec
    if line =~ /\| PASSED:/
      $passed_lines = $passed_lines +1
    end
    # Faillog for MSpec
    if line =~ /\| FAIL:/
      line = line.gsub(/I.*APP\|/,"\n\n***")
      if !$faillog.include?(line)
        $faillog << line
      end
      $failed_lines = $failed_lines +1
      $getdump = true
    end
    # Faillog for Jusmine
    if line =~ /I.* Jasmine specRunner\| .*Failed\./
      line = line.gsub(/I.*Jasmine specRunner\|/,"\n\n***")
      if !$faillog.include?(line)
        $faillog << line
      end
      $failed_lines = $failed_lines +1
      $getdump = true
    end

    print_statistic_in_progress

    return true
end

.process_spec_results(start) ⇒ Object



460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/build/jake.rb', line 460

def self.process_spec_results(start)
  finish = Time.now

  jpath = File.join($app_path,'junitrep')

  # remove old spec results
  test_patterns = ['Test*.xml', '*_spec_results.xml']
  base_path = File.join($app_path,'**')
  Dir.glob( test_patterns.map{ |pat| File.join(base_path, pat) } ).each { |file_name| File.delete(file_name) }

  FileUtils.rm_rf jpath

  FileUtils.mkdir_p jpath

  $junitlogs.each do |name, log|
    if log.length > 0
      File.open(File.join(jpath,"#{name}.xml"), "w") { |io| io << log.join().gsub('~~',$/) }
    end
  end

  FileUtils.rm_rf $app_path + "/faillog.txt"

  if $failed.to_i > 0
    log Logger::ERROR, "************************"
    log Logger::ERROR, "\n\n"
    $faillog.each {|x| log Logger::ERROR, x }
    File.open($app_path + "/faillog.txt", "w") { |io| $faillog.each {|x| io << x }  }
  end

  log(Logger::INFO, "\n")
  log(Logger::INFO,"************************")
  log(Logger::INFO,"Tests completed in #{"%.1f" % (finish - start)} seconds")
  log(Logger::INFO,"Total: #{$total}")
  log(Logger::INFO,"Passed: #{$passed}")
  log(Logger::INFO,"Failed: #{$failed}")
  log(Logger::INFO,"Not supported by Rhodes: #{$notsupported}")
  log(Logger::INFO,"Failures stored in faillog.txt") if $failed.to_i > 0
  log(Logger::INFO,"MSpec tests: #{$mspec_lines}")
  log(Logger::INFO,"Jasmine tests: #{$jasmine_lines}")
  log(Logger::INFO,"Passed checks: #{$passed_lines}")
  log(Logger::INFO,"Failed checks: #{$failed_lines}")
  log(Logger::INFO,"************************")
  log(Logger::INFO,"\n")
end

.rapc(output, destdir, imports, files, title = nil, vendor = nil, version = nil, icon = nil, library = true, cldc = false, quiet = true, nowarn = true) ⇒ Object



777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'lib/build/jake.rb', line 777

def self.rapc(output,destdir,imports,files,title=nil,vendor=nil,version=nil,icon=nil,library=true,cldc=false,quiet=true, nowarn=true)
  #cmd = $config["env"]["paths"][$config["env"]["bbver"]]["java"] + "/java.exe"
#   cmd = "java.exe"

  jdehome = $config["env"]["paths"][@@bbver]["jde"]
  javabin = $config["env"]["paths"]["java"]
  cmd = jdehome + "/bin/rapc.exe"

  currentdir = Dir.pwd()


  Dir.chdir destdir

  if output and title and version and vendor
    f = File.new(output + ".rapc", "w")
    f.write "MicroEdition-Profile: MIDP-2.0\n"
    f.write "MicroEdition-Configuration: CLDC-1.1\n"
    f.write "MIDlet-Name: " + title + "\n"
    f.write "MIDlet-Version: " + version.to_s + "\n"
    f.write "MIDlet-Vendor: " + vendor.to_s + "\n"
    f.write "MIDlet-Jar-URL: " + output + ".jar\n"
    f.write "MIDlet-Jar-Size: 0\n"
    f.write "RIM-Library-Flags: 2\n" if library

    if cldc and icon
      f.write "MIDlet-1: " + title + "," + icon + ",\n"
      log Logger::DEBUG,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! service_enabled: #{$service_enabled}"
      $stdout.flush

        if $service_enabled
          if $hidden_app == "0"
              f.write "RIM-MIDlet-Flags-1: 1\n"
          else
              f.write "RIM-MIDlet-Flags-1: 3\n"
          end
        else
          if $hidden_app == "0"
              f.write "RIM-MIDlet-Flags-1: 0\n"
          else
              f.write "RIM-MIDlet-Flags-1: 2\n"
          end
        end

    end

    f.close
  end


  args = []
  #args << "-classpath"
#  args << "-jar"
  #args << jdehome + "/bin/rapc.jar"
  #args << "net.rim.tools.compiler.Compiler"

  args << "-javacompiler=" + javabin + "/javac.exe"
  args << "-quiet" if quiet
  args << "-nowarn" if nowarn
  args << 'import=' + imports
  args << 'codename=' + output
  args << 'library=' + output if library
  args << output + '.rapc'
  args << files

  cmd.gsub!(/\//,"\\")
  outputstring = run(cmd, args)
  log(Logger::DEBUG,outputstring) unless $? == 0
  Dir.chdir currentdir

end

.reset_bulk_serverObject



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/build/jake.rb', line 314

def self.reset_bulk_server()
	require 'rest_client'
	require 'json'

	begin
platform = platform
exact_url = BULK_SYNC_SERVER_URL
log Logger::INFO, "going to reset server: #{exact_url}"
# login to the server
unless @bulk_srv_token
	@bulk_srv_token = RestClient.post("#{exact_url}/rc/v1/system/login", { :login => BULK_SYNC_SERVER_CONSOLE_LOGIN, :password => BULK_SYNC_SERVER_CONSOLE_PASSWORD }.to_json, :content_type => :json)
end
RestClient.post("#{exact_url}/api/reset", {:api_token => @bulk_srv_token}.to_json, :content_type => :json)
log Logger::INFO, "reset OK"
  rescue Exception => e
log Logger::ERROR, "reset_bulk_server failed: #{e}"
	end
end

.reset_spec_server(platform) ⇒ Object



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/build/jake.rb', line 294

def self.reset_spec_server(platform)
  require 'rest_client'
  require 'json'

  begin
      platform = platform
      exact_url = SYNC_SERVER_BASE_URL.gsub(/exact_platform/, platform)
      log Logger::INFO, "going to reset server: #{exact_url}"
      # login to the server
      unless @srv_token
  @srv_token = RestClient.post("#{exact_url}/rc/v1/system/login", { :login => SYNC_SERVER_CONSOLE_LOGIN, :password => SYNC_SERVER_CONSOLE_PASSWORD }.to_json, :content_type => :json)
      end
      # reset server
      RestClient.post("#{exact_url}/api/reset", {:api_token => @srv_token}.to_json, :content_type => :json)
log Logger::INFO, "reset OK"
  rescue Exception => e
    log Logger::ERROR, "reset_spec_server failed: #{e}"
  end
end

.run(command, args, wd = nil, system = false, hideerrors = false) ⇒ Object



578
579
580
# File 'lib/build/jake.rb', line 578

def self.run(command, args, wd=nil,system = false, hideerrors = false)
  self.run2(command, args, {:directory => wd, :system => system, :hiderrors => hideerrors})
end

.run2(command, args, options = {}, &block) ⇒ Object



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/build/jake.rb', line 505

def self.run2(command, args, options = {}, &block)
	argv = []
	currentdir = ""
	retval = ""
	argv << command
	argv += args
	argv.map! { |x| x.to_s }.map! { |x| x =~ /^".*"$/ ? x[1..-2] : x }

	wd = options[:directory]
	if not wd.nil?
    currentdir = Dir.pwd()
    Dir.chdir wd
  end

  cmdstr = argv.map { |x| x =~ / |\|/ ? '"' + x + '"' : x }.join(' ')

  if options[:string_for_add_to_command_line] != nil
    cmdstr = cmdstr + options[:string_for_add_to_command_line]
  end

  $stdout.flush
  unless options[:hide_output]
    log Logger::DEBUG,"PWD: #{Dir.pwd()}"
    log Logger::DEBUG,"CMD: #{cmdstr}"
    $stdout.flush
  end

  hideerrors = options[:hideerrors]
  if hideerrors
    if RUBY_PLATFORM =~ /(win|w)32$/
      nul = "nul"
    else
      nul = "/dev/null"
    end
  end

  if options[:system]
    system(cmdstr)
    retval = ""
  else
    # this check was commented by crash on 1.9.2 Ruby on Mac OS
    argv = cmdstr #if RUBY_VERSION =~ /^1\.8/
    if options[:nowait]
      retval = IO.popen(argv)
    else
      puts "$$$ RUN COMMAND = "+argv.to_s  
      IO.popen(argv) do |f|
        while line = f.gets
          if block_given?
              res = yield(line)
              if !res
                  #puts "f.pid : #{f.pid}"
                  Process.kill( 9, f.pid )
              end
          else
              retval += line
unless options[:hide_output]
                  log Logger::DEBUG,"RET: #{line}"
                  $stdout.flush
end
          end
        end
      end
    end
  end

  if not wd.nil?
    Dir.chdir currentdir
  end

  retval
end

.run3(command, cd = nil, env = {}, use_run2 = false) ⇒ Object



637
638
639
# File 'lib/build/jake.rb', line 637

def self.run3(command, cd = nil, env = {}, use_run2 = false)
  fail "[#{command}]" unless self.run3_dont_fail(command, cd, env, use_run2)
end

.run32(command, cd = nil, env = {}) ⇒ Object



632
633
634
# File 'lib/build/jake.rb', line 632

def self.run32(command, cd = nil, env = {})
  fail "[#{command}]" unless self.run3_dont_fail(command, cd, env, true)
end

.run3_dont_fail(command, cd = nil, env = {}, use_run2 = false) ⇒ Object



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/build/jake.rb', line 582

def self.run3_dont_fail(command, cd = nil, env = {}, use_run2 = false)
  set_list = []
	currentdir = ""
  env.each_pair do |k, v|
    if RUBY_PLATFORM =~ /(win|w)32$/
      set_list << "set \"#{k}=#{v}\"&&"
    else
      set_list << "export #{k}=#{v}&&"
    end
  end

  to_print = "CMD: #{command}"
  to_run = set_list.join('') + command
  if !cd.nil?
    to_print = "PWD: #{cd}\n#{to_print}"

    if RUBY_PLATFORM =~ /(win|w)32$/
      cd_ = cd.gsub('/', "\\")
      to_run = "cd /d \"#{cd_}\"&&#{to_run}"
    else
      if use_run2
        currentdir = Dir.pwd()
        Dir.chdir cd
      else
        to_run = "cd '#{cd}'&&#{to_run}"
      end
    end
  end

  if !env.nil?
    to_print = "ENV: #{env}\n#{to_print}"
  end

  log Logger::DEBUG,to_print
  STDOUT.flush

  if use_run2
      self.run2(to_run, []) do |line|
          log Logger::DEBUG,line
      end
      if not cd.nil?
        Dir.chdir currentdir
      end
      return $?.exitstatus == 0
  else
      res = system(to_run)
      return res
  end
end

.run4(command) ⇒ Object



641
642
643
644
645
# File 'lib/build/jake.rb', line 641

def self.run4(command)
    out = `#{command}`
    fail "[#{command}]" if $?.exitstatus != 0
    out
end

.run_local_server(port = 0) ⇒ Object



270
271
272
273
274
275
276
277
278
279
# File 'lib/build/jake.rb', line 270

def self.run_local_server(port = 0)
  require 'webrick'

  addr = localip                   #:BindAddress => addr,
  server = WEBrick::HTTPServer.new :Port => port
  port = server.config[:Port]
  log Logger::INFO, "LOCAL SERVER STARTED ON #{addr}:#{port}"
  Thread.new { server.start }
  return server, addr, port
end

.run_local_server_with_logger(port, log_file) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/build/jake.rb', line 281

def self.run_local_server_with_logger(port, log_file)
  require 'webrick'

  addr = localip
  log = WEBrick::Log.new log_file
  access_log = [[log_file, WEBrick::AccessLog::COMBINED_LOG_FORMAT]]
  server = WEBrick::HTTPServer.new :Port => port, :Logger => log, :AccessLog => access_log
  port = server.config[:Port]
  # puts "LOCAL SERVER STARTED ON #{addr}:#{port}"
  Thread.new { server.start }
  return server, addr, port
end

.run_rho_log_server(app_path) ⇒ Object



1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
# File 'lib/build/jake.rb', line 1186

def self.run_rho_log_server(app_path)
  require 'webrick'

  confpath_content = File.read($srcdir + "/apps/rhoconfig.txt") if File.exists?($srcdir + "/apps/rhoconfig.txt")
  confpath_content += "\r\n" + "rhologurl=http://" + $rhologhostaddr + ":" + $rhologhostport.to_s() if !confpath_content.include?("rhologurl=")
  confpath_content += "\r\n" + "LogToSocket=1" if !confpath_content.include?("LogToSocket=")
  File.open($srcdir + "/apps/rhoconfig.txt", "w") { |f| f.write(confpath_content) }  if confpath_content && confpath_content.length()>0

  begin
      require 'net/http'

      res = Net::HTTP.start(Jake.localip(), $rhologhostport) {|http|
           http.post('/', "RHOLOG_GET_APP_NAME")
      }
      puts "res : #{res}"
      puts "body : #{res.body}"

      if ( res && res.body == app_path)
          puts "Log server is already running. Reuse it."

       started = File.open($app_path + "/started", "w+")
       started.close

          return
      else
          puts "Close Log server for another app."
          res = Net::HTTP.start(Jake.localip(), $rhologhostport) {|http|
               http.post('/', "RHOLOG_CLOSE")
          }

      end
  rescue Exception => e
      puts "EXC: #{e}"
  end

  system("START rake run:webrickrhologserver[\"#{app_path}\"]")
end

.run_with_output(command, options = {}) ⇒ Object

will exec command and return stdout and stderr. options are to be extended for updated functionality



648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/build/jake.rb', line 648

def self.run_with_output( command, options = {} )
  require 'open3'
  poutres = ''
  perrres = ''
  wtr = nil
  Open3.popen3(command) do |pin,pout,perr,wait_thr|
    while line = pout.gets
      poutres << line
    end

    while line = perr.gets
      perrres << line
    end

    wtr = wait_thr
  end

  return poutres, perrres, wtr
end

.set_bbver(bbver) ⇒ Object



192
193
194
# File 'lib/build/jake.rb', line 192

def self.set_bbver(bbver)
  @@bbver = bbver
end

.set_logger(logger) ⇒ Object



147
148
149
# File 'lib/build/jake.rb', line 147

def self.set_logger(logger)
  @@logger = logger
end

.setBuildProp(propName, propValue, config_yml = $app_config) ⇒ Object



1252
1253
1254
# File 'lib/build/jake.rb', line 1252

def self.setBuildProp(propName, propValue, config_yml=$app_config)
  config_yml[propName] = propValue
end

.unjar(src, targetdir) ⇒ Object



707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'lib/build/jake.rb', line 707

def self.unjar(src,targetdir)
  jpath = $config["env"]["paths"]["java"]
  cmd = jpath && jpath.length()>0 ? File.join(jpath, "jar" ) : "jar"

#    if RUBY_PLATFORM =~ /(win|w)32$/
#      cmd =  $config["env"]["paths"]["java"] + "/jar.exe"
#    else
#      cmd =  $config["env"]["paths"]["java"] + "/jar"
#    end

    p = Pathname.new(src)
  src = p.realpath
  currentdir = Dir.pwd()
  src = src.to_s.gsub(/"/,"")

  args = Array.new

  args << "xf"
  args << src.to_s

  Dir.chdir targetdir
  log Logger::DEBUG,run(cmd,args)
  Dir.chdir currentdir
end

.unzip(src_zip, dest_dir) ⇒ Object

Unzips archive to specified directory

Parameters:

  • src_zip (String)

    absolute path to archive

  • dest_dir (String)

    path to directory when archive will be unzipped. If it not exists it will be created. It could contain nested directories

  • block (block, optional)

    Block code will be called before each file entry extracting and it’s parameters are: file entry size in bytes, archive total size in bytes, string like “Unpacking files: NN%” where NN% - unzipping progress in percents



1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
# File 'lib/build/jake.rb', line 1019

def self.unzip(src_zip, dest_dir)
  require 'zip'
  require 'fileutils'

  unless File.exist?(dest_dir)
    FileUtils.mkdir_p(dest_dir)
  end

  Zip::File.open(src_zip) do |zip_file|

    unzipped_bytes = 0
    total_bytes = zip_file.inject(0) { |result, each| result  + each.size }

    zip_file.each do |entry|

      if block_given? and entry.size != 0
        unzipped_bytes = unzipped_bytes + entry.size
        yield(unzipped_bytes, total_bytes, "Unpacking files: #{(unzipped_bytes * 100) / total_bytes}%")
      end
      file_dir_name = File.join(dest_dir,File.dirname(entry.name))
      FileUtils::mkdir_p file_dir_name unless Dir.exists?(file_dir_name)
      entry.extract(File.join(dest_dir, entry.name))

    end
  end

end

.zip(where, what, dest) ⇒ Object

Zips specified files from directory

Parameters:

  • where (String)

    absolute path to base directory with files fir zipping

  • what (Array)

    Array of file path of files to zipping. Each file path is relative for where argument

  • dest (String)

    File path to created archive. If file already exists it will be removed before archive creation



1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
# File 'lib/build/jake.rb', line 1051

def self.zip(where, what, dest)
  require 'zip'

  if File.exist?(dest)
    FileUtils.rm(dest);
  end

  Zip::File.open(dest, Zip::File::CREATE) do |zipfile|
    what.each do |filename|
      zipfile.add(filename, File.join(where, filename))
    end
  end
end

.zip_upgrade_bundle(folder_path, zip_file_path) ⇒ Object



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
# File 'lib/build/jake.rb', line 1065

def self.zip_upgrade_bundle(folder_path, zip_file_path)

  require 'zip'

  current_dir = Dir.pwd()
  begin
    Dir.chdir(folder_path)
    File.delete(zip_file_path) if File.exists?(zip_file_path)

    items_to_zip = []

    Zip::File.open(zip_file_path, Zip::File::CREATE) do |zip_file|
      (Dir['RhoBundle/**/*']).each { |path|
        exclude_items = (Jake.getBuildProp2('rhobundle', 'exclude_items') || []).collect { |each| %r{#{each}} }
        begin
          log Logger::INFO,"Excluded: #{path}".warning
          next
        end if (exclude_items.any? { |each| path.index(each) })
        log Logger::INFO,"added to zip : #{path}"
        zip_file.add(path, path)
      }
    end
  ensure
    Dir.chdir(current_dir)
  end
end