forked from ruboto/ruboto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
691 lines (603 loc) · 22.1 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
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
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
78
79
80
81
82
83
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
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
459
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
504
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
577
578
579
580
581
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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
$:.unshift('lib') unless $:.include?('lib')
require 'time'
require 'date'
require 'rake/clean'
require 'rexml/document'
require 'ruboto/version'
require 'ruboto/description'
require 'ruboto/sdk_versions'
require 'uri'
require 'net/http'
require 'net/https'
require 'openssl'
require 'yaml'
PROJECT_DIR = File.expand_path(File.dirname(__FILE__))
PLATFORM_PROJECT = File.expand_path('tmp/RubotoCore', File.dirname(__FILE__))
PLATFORM_DEBUG_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-debug.apk"
PLATFORM_DEBUG_APK_BAK = "#{PLATFORM_PROJECT}/bin/RubotoCore-debug.apk.bak"
PLATFORM_RELEASE_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-release.apk"
PLATFORM_CURRENT_RELEASE_APK = File.expand_path('tmp/RubotoCore-release.apk', File.dirname(__FILE__))
MANIFEST_FILE = 'AndroidManifest.xml'
GEM_FILE = "ruboto-#{Ruboto::VERSION}.gem"
GEM_SPEC_FILE = 'ruboto.gemspec'
README_FILE = 'README.md'
WEB_DIR = "#{File.dirname PROJECT_DIR}/ruboto.github.com"
BLOG_DIR = '_posts'
RELEASE_BLOG = "#{BLOG_DIR}/#{Date.today}-Ruboto-#{Ruboto::VERSION}-release-doc.md"
RELEASE_BLOG_GLOB = "#{BLOG_DIR}/*-Ruboto-#{Ruboto::VERSION}-release-doc.md"
RELEASE_CANDIDATE_DOC = 'RELEASE_CANDICATE_DOC.md'
RELEASE_DOC = 'RELEASE_DOC.md'
CLEAN.include('ruboto-*.gem', 'tmp')
task :default => :gem
desc 'Generate a gem'
task :gem => GEM_FILE
file GEM_FILE => GEM_SPEC_FILE do
puts "Generating #{GEM_FILE}"
`gem build #{GEM_SPEC_FILE}`
end
task :install => :gem do
old_rubyopt = ENV['RUBYOPT']
ENV['RUBYOPT'] = nil
`gem query -i -n ^ruboto$ -v #{Ruboto::VERSION}`
if $? != 0
puts 'Installing gem'
cmd = "gem install ruboto-#{Ruboto::VERSION}.gem"
output = `#{cmd}`
if $? == 0
puts output
else
sh "sudo #{cmd}"
end
else
puts "ruboto-#{Ruboto::VERSION} is already installed."
end
ENV['RUBYOPT'] = old_rubyopt
end
task :uninstall do
old_rubyopt = ENV['RUBYOPT']
ENV['RUBYOPT'] = nil
`gem query -i -n ^ruboto$ -v #{Ruboto::VERSION}`
if $? == 0
puts 'Uninstalling gem'
cmd = "gem uninstall -x ruboto -v #{Ruboto::VERSION}"
output = `#{cmd}`
if $? == 0
puts output
else
sh "sudo #{cmd}"
end
else
puts "ruboto-#{Ruboto::VERSION} is not installed."
end
ENV['RUBYOPT'] = old_rubyopt
end
task :reinstall => [:uninstall, :clean, :install]
desc 'Generate an example app'
task :example => :install do
require 'ruboto/sdk_locations'
EXAMPLE_FILE = File.expand_path("examples/RubotoTestApp_#{Ruboto::VERSION}_tools_r#{Ruboto::SdkLocations::ANDROID_TOOLS_REVISION}.tgz", File.dirname(__FILE__))
EXAMPLES_GLOB = "#{EXAMPLE_FILE.slice(/^.*?_\d+\.\d+\.\d+/)}*"
sh "git rm #{EXAMPLES_GLOB}" unless Dir[EXAMPLES_GLOB].empty?
puts "Creating example app #{EXAMPLE_FILE}"
app_name = 'RubotoTestApp'
Dir.chdir File.dirname(EXAMPLE_FILE) do
FileUtils.rm_rf app_name
sh "ruboto gen app --package org.ruboto.test_app --name #{app_name} --path #{app_name}"
Dir.chdir app_name do
sh 'rake patch_dex'
Dir.chdir 'test' do
sh 'ant instrument' # This will also build the main project.
end
end
sh "tar czf #{EXAMPLE_FILE} #{app_name}"
FileUtils.rm_rf app_name
end
end
class String
def wrap(indent = 0)
line_length = 72-indent
scan(/\S.{0,#{line_length}}\S(?=\s|$)|\S+/).join("\n" + ' ' * indent)
end
end
desc 'Update the README with the Ruboto description.'
file README_FILE => 'lib/ruboto/description.rb' do
File.write(README_FILE, File.read(README_FILE).sub(/(?<=\n\n).*(?=\nInstallation)/m, Ruboto::DESCRIPTION))
end
desc 'Generate release docs for a given milestone'
def get_github_issues
puts 'GitHub login:'
begin
require 'rubygems'
require 'highline/import'
user = ask('login : ') { |q| q.echo = true }
pass = ask('password: ') { |q| q.echo = '*' }
rescue Exception
print 'user name: '; user = STDIN.gets.chomp
print ' password: '; pass = STDIN.gets.chomp
end
host = 'api.github.com'
base_uri = "https://#{host}/repos/ruboto/ruboto"
https = Net::HTTP.new(host, 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
milestone_uri = URI("#{base_uri}/milestones")
req = Net::HTTP::Get.new(milestone_uri.request_uri)
req.basic_auth(user, pass)
res = https.start { |http| http.request(req) }
milestones = YAML.load(res.body).sort_by { |i| Date.parse(i['due_on']) }
milestone_entry = milestones.find { |m| m['title'] == Ruboto::VERSION.chomp('.dev') }
raise "Milestone for version #{Ruboto::VERSION} not found." unless milestone_entry
milestone = milestone_entry['number']
uri = URI("#{base_uri}/issues?milestone=#{milestone}&state=closed&per_page=1000")
req = Net::HTTP::Get.new(uri.request_uri)
req.basic_auth(user, pass)
res = https.start { |http| http.request(req) }
issues = YAML.load(res.body).sort_by { |i| i['number'] }
milestone_name = issues[0] ? issues[0]['milestone']['title'] : "No issues for milestone #{milestone}"
milestone_description = issues[0] ? issues[0]['milestone']['description'] : "No issues for milestone #{milestone}"
milestone_description = milestone_description.split("\r\n").map(&:wrap).join("\r\n")
categories = {
'Features' => 'feature', 'Bugfixes' => 'bug',
'Performance' => 'performance', 'Documentation' => 'documentation',
'Support' => 'support', 'Community' => 'community',
'Pull requests' => nil, 'Internal' => 'internal',
'Rejected' => 'rejected', 'Other' => nil
}
grouped_issues = issues.group_by do |i|
labels = i['labels'].map { |l| l['name'] }
cat = nil
categories.each do |k, v|
if labels.include? v
cat = k
break
end
end
cat ||= i['pull_request'] && i['pull_request']['html_url'] && 'Pull requests'
cat ||= 'Other'
cat
end
return categories, grouped_issues, milestone, milestone_description, milestone_name
end
task :release_docs do
raise "\n This task requires Ruby 1.9 or newer to parse JSON as YAML.\n\n" if RUBY_VERSION == '1.8.7'
categories, grouped_issues, milestone, milestone_description, milestone_name = get_github_issues
puts '=' * 80
puts
release_candidate_doc = <<EOF
Subject: [ANN] Ruboto #{milestone_name} release candidate
Hi all!
The Ruboto #{milestone_name} release candidate is now available.
#{milestone_description}
As always we need your help and feedback to ensure the quality of the release. Please install the release candidate using
[sudo] gem install ruboto --pre
and test your apps after updating with
ruboto update app
If you have an app released for public consumption, please let us know. Our developer program seeks to help developers getting started using Ruboto, and ensure good quality across Ruboto releases. Currently we are supporting the apps listed here:
https://github.com/ruboto/ruboto/wiki/Promoted-apps
If you are just starting with Ruboto, but still want to contribute, please select and complete one of the tutorials and mark it with the version of Ruboto you used.
https://github.com/ruboto/ruboto/wiki/Tutorials-and-examples
If you find a bug or have a suggestion, please file an issue in the issue tracker:
https://github.com/ruboto/ruboto/issues
--
The Ruboto Team
http://ruboto.org/
EOF
puts release_candidate_doc
File.write(RELEASE_CANDIDATE_DOC, release_candidate_doc)
sh "git add -f #{RELEASE_CANDIDATE_DOC}"
puts
puts '=' * 80
puts
release_doc = <<EOF
Subject: [ANN] Ruboto #{milestone_name} released!
The Ruboto team is pleased to announce the release of Ruboto #{milestone_name}.
#{Ruboto::DESCRIPTION.gsub("\n", ' ').wrap}
New in version #{milestone_name}:
#{milestone_description}
#{(categories.keys & grouped_issues.keys).map do |cat|
"#{cat}:\n
#{grouped_issues[cat].map { |i| %Q{* Issue ##{i['number']} #{i['title'].gsub('`', "'")}#{" (#{i['user']['login']})" if i['pull_request'] && i['pull_request']['html_url']}}.wrap(2) }.join("\n")}
"
end.join("\n")}
You can find a complete list of issues here:
* https://github.com/ruboto/ruboto/issues?state=closed&milestone=#{milestone}
Installation:
To use Ruboto, you need to install a Ruby implementation. Then do
(possibly as root/administrator)
gem install ruboto
ruboto setup -y
To create a project do
ruboto gen app --package <your.package.name>
cd <project directory>
ruboto setup -y
To run an emulator for your project
cd <project directory>
ruboto emulator
To run your project
cd <project directory>
rake install start
You can find an introductory tutorial at
https://github.com/ruboto/ruboto/wiki
If you have any problems or questions, come see us at http://ruboto.org/
Enjoy!
--
The Ruboto Team
http://ruboto.org/
EOF
puts release_doc
puts
puts '=' * 80
File.write(RELEASE_DOC, release_doc)
unless Gem::Version.new(Ruboto::VERSION).prerelease?
header = <<EOF
---
title : Ruboto #{Ruboto::VERSION}
layout: post
category: news
---
EOF
Dir.chdir WEB_DIR do
output = `git status --porcelain`
old_blog_posts = Dir[RELEASE_BLOG_GLOB] - [RELEASE_BLOG]
sh "git rm -f #{old_blog_posts.join(' ')}" unless old_blog_posts.empty?
File.write(RELEASE_BLOG, header + release_doc)
end
end
end
desc 'Fetch download stats form rubygems.org'
task :stats do
host = 'rubygems.org'
base_uri = "https://#{host}/api/v1"
https = Net::HTTP.new(host, 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
counts_per_month = Hash.new { |h, k| h[k] = Hash.new { |mh, mk| mh[mk] = 0 } }
total = 0
%w{ruboto-core ruboto}.each do |gem|
versions_uri = URI("#{base_uri}/versions/#{gem}.yaml")
req = Net::HTTP::Get.new(versions_uri.request_uri)
res = https.start { |http| http.request(req) }
versions = YAML.load(res.body).sort_by { |v| Gem::Version.new(v['number']) }
puts "\n#{gem}:\n#{versions.map { |v| "#{Time.parse(v['built_at']).strftime('%Y-%m-%d')} #{'%10s' % v['number']} #{v['downloads_count']}" }.join("\n")}"
versions.each do |v|
downloads_uri = URI("#{base_uri}/versions/#{gem}-#{v['number']}/downloads/search.yaml?from=#{Time.parse(v['built_at']).strftime('%Y-%m-%d')}&to=#{Date.today}")
req = Net::HTTP::Get.new(downloads_uri.request_uri)
res = https.start { |http| http.request(req) }
counts = YAML.load(res.body)
counts.delete_if { |date_str, count| count == 0 }
counts.each do |date_str, count|
date = Date.parse(date_str)
counts_per_month[date.year][date.month] += count
total += count
end
print '.'; STDOUT.flush
end
puts
end
puts "\nDownloads statistics per month:"
years = counts_per_month.keys
puts "\n #{years.map { |year| '%6s:' % year }.join(' ')}"
(1..12).each do |month|
print "#{'%2d' % month}:"
years.each do |year|
count = counts_per_month[year][month]
print count > 0 ? '%8d' % count : ' ' * 8
end
puts
end
puts "\nTotal: #{total}\n\n"
puts "\nRubyGems download statistics per month:"
years = counts_per_month.keys
puts ' ' + years.map { |year| '%-12s' % year }.join
(0..20).each do |l|
print (l % 10 == 0) ? '%4d' % ((20-l) * 100) : ' '
years.each do |year|
(1..12).each do |month|
count = counts_per_month[year][month]
if [year, month] == [Date.today.year, Date.today.month]
count *= (Date.new(Date.today.year, Date.today.month, -1).day.to_f / Date.today.day).to_i
end
print count > ((20-l) * 100) ? '*' : ' '
end
end
puts
end
puts ' ' + years.map { |year| '%-12s' % year }.join
puts "\nTotal: #{total}\n\n"
end
desc 'Push the gem to RubyGems'
task :release => [:clean, README_FILE, :release_docs, :gem] do
output = `git status --porcelain`
raise "Workspace not clean!\n#{output}" unless output.empty?
Dir.chdir WEB_DIR do
output = `git status --porcelain`
raise "Web workspace not clean!\n#{output}" unless output.empty?
sh "git add -f #{RELEASE_BLOG}"
`git commit -m "* Added release blog for Ruboto #{Ruboto::VERSION}"`
sh 'git push'
end
sh "git tag #{Ruboto::VERSION}"
sh 'git push --tags'
sh "gem push #{GEM_FILE}"
Rake::Task[:example].invoke
sh "git add #{EXAMPLE_FILE}"
sh "git commit -m '* Added example app for Ruboto #{Ruboto::VERSION} tools r#{Ruboto::SdkLocations::ANDROID_TOOLS_REVISION}' \"#{EXAMPLES_GLOB}\""
sh 'git push'
end
desc "Run the tests. Select which test files to load with 'rake test TEST=test_file_pattern'"
task :test do
FileUtils.rm_rf Dir['tmp/RubotoTestApp_template*']
test_pattern = ARGV.grep(/^TEST=.*$/)
ARGV.delete_if { |a| test_pattern.include? a }
test_pattern.map! { |t| t[5..-1] }
$: << File.expand_path('test', File.dirname(__FILE__))
test_files = (test_pattern.any? ? test_pattern : %w(test/*_test.rb)).
map { |d| Dir[d] }.flatten.sort
if /(\d+)OF(\d+)/i =~ ENV['TEST_PART']
part_index = $1.to_i - 1
parts = $2.to_i
total_tests = test_files.size
files_in_part = total_tests.to_f / parts
start_index = (files_in_part * part_index).round
end_index = (files_in_part * (part_index + 1)).round - 1
test_files = test_files[start_index..end_index]
puts "Running tests #{start_index + 1}-#{end_index + 1} of #{total_tests}"
end
test_files.each do |f|
require f.chomp('.rb')[5..-1]
end
end
namespace :platform do
desc 'Remove Ruboto Core platform project'
task :clean do
FileUtils.rm_rf PLATFORM_PROJECT
end
desc 'Generate the Ruboto Core platform project'
task :project => PLATFORM_PROJECT
file PLATFORM_PROJECT do
sh "git clone --depth 1 https://github.com/ruboto/ruboto-core.git #{PLATFORM_PROJECT}"
Dir.chdir PLATFORM_PROJECT do
sh "ruby -rubygems -I#{File.expand_path('lib', File.dirname(__FILE__))} ../../bin/ruboto update app --force"
end
end
desc 'Generate a Ruboto Core platform debug apk'
task :debug => PLATFORM_DEBUG_APK
task PLATFORM_DEBUG_APK do
Rake::Task[PLATFORM_PROJECT].invoke
Dir.chdir(PLATFORM_PROJECT) do
if File.exists?(PLATFORM_DEBUG_APK_BAK)
FileUtils.cp PLATFORM_DEBUG_APK_BAK, PLATFORM_DEBUG_APK
else
FileUtils.rm PLATFORM_DEBUG_APK
end
sh 'rake debug'
end
end
desc 'Generate a Ruboto Core platform release apk'
task :release => PLATFORM_RELEASE_APK
file PLATFORM_RELEASE_APK => PLATFORM_PROJECT do
Dir.chdir(PLATFORM_PROJECT) do
sh 'rake release'
end
end
desc 'Download the current RubotoCore platform release apk'
file PLATFORM_CURRENT_RELEASE_APK do
FileUtils.mkdir_p File.dirname(PLATFORM_CURRENT_RELEASE_APK)
puts 'Downloading the current RubotoCore platform release apk'
uri = URI('https://raw.github.com/ruboto/ruboto.github.com/master/downloads/RubotoCore-release.apk')
begin
headers = {'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; de-at) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10'}
catch :download_ok do
loop do
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https',
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
response = http.get(uri.request_uri, headers)
if response.code == '200'
File.open(PLATFORM_CURRENT_RELEASE_APK, 'wb') { |f| f << response.body }
throw :download_ok
elsif response.code == '301' || response.code == '302'
headers.update('Referer' => uri.to_s)
if (cookie = response.response['set-cookie'])
headers.update('Cookie' => cookie)
end
uri = URI(response['location'].gsub(/^\//, 'http://ruboto.org/'))
puts "Following redirect to #{uri}."
else
puts "Got an unexpected response (#{response.code}). Retrying download."
puts response.inspect
sleep 1
end
end
end
end
rescue Exception, SystemExit
puts "Download failed: #{$!}"
FileUtils.rm(PLATFORM_CURRENT_RELEASE_APK) if File.exists?(PLATFORM_CURRENT_RELEASE_APK)
raise
end
end
desc 'Install the current RubotoCore platform release apk'
task :current => PLATFORM_CURRENT_RELEASE_APK do
install_apk
end
desc 'Install the Ruboto Core platform debug apk'
task :install => PLATFORM_PROJECT do
Dir.chdir(PLATFORM_PROJECT) do
sh 'rake install'
end
end
desc 'Uninstall the Ruboto Core platform debug apk'
task :uninstall do
uninstall_apk
end
private
def package
'org.ruboto.core'
end
def wait_for_valid_device
while `adb shell echo "ping"`.strip != 'ping'
`adb kill-server`
`adb devices`
sleep 5
end
end
def install_apk
wait_for_valid_device
failure_pattern = /^Failure \[(.*)\]/
success_pattern = /^Success/
install_timeout = 300
case package_installed?
when true
puts "Package #{package} already installed."
return
when false
puts "Package #{package} already installed, but of different size or timestamp. Replacing package."
sh "adb shell date -s #{Time.now.strftime '%Y%m%d.%H%M%S'}"
output = nil
install_retry_count = 0
begin
timeout install_timeout do
output = `adb install -r "#{PLATFORM_CURRENT_RELEASE_APK}" 2>&1`
end
rescue Timeout::Error
puts "Installing package #{package} timed out."
install_retry_count += 1
if install_retry_count <= 3
puts 'Retrying install...'
retry
end
puts 'Trying one final time to install the package:'
output = `adb install -r "#{PLATFORM_CURRENT_RELEASE_APK}" 2>&1`
end
if $? == 0 && output !~ failure_pattern && output =~ success_pattern
return
end
case $1
when 'INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES'
puts 'Found package signed with different certificate. Uninstalling it and retrying install.'
else
puts "'adb install' returned an unknown error: (#$?) #{$1 ? "[#$1}]" : output}."
puts "Uninstalling #{package} and retrying install."
end
uninstall_apk
else
# Package not installed.
sh "adb shell date -s #{Time.now.strftime '%Y%m%d.%H%M%S'}"
end
puts "Installing package #{package}"
output = nil
install_retry_count = 0
begin
timeout install_timeout do
output = `adb install "#{PLATFORM_CURRENT_RELEASE_APK}" 2>&1`
end
rescue Timeout::Error
puts "Installing package #{package} timed out."
install_retry_count += 1
if install_retry_count <= 3
puts 'Retrying install...'
retry
end
puts 'Trying one final time to install the package:'
install_start = Time.now
output = `adb install "#{PLATFORM_CURRENT_RELEASE_APK}" 2>&1`
puts "Install took #{(Time.now - install_start).to_i}s."
end
puts output
raise "Install failed (#{$?}) #{$1 ? "[#$1}]" : output}" if $? != 0 || output =~ failure_pattern || output !~ success_pattern
end
def uninstall_apk
return if package_installed?.nil?
puts "Uninstalling package #{package}"
system "adb uninstall #{package}"
if $? != 0 && package_installed?
puts "Uninstall failed exit code #{$?}"
exit $?
end
end
def package_installed?
package_name = package
%w( -0 -1 -2).each do |i|
path = "/data/app/#{package_name}#{i}.apk"
o = `adb shell ls -l #{path}`.chomp
if o =~ /^-rw-r--r-- system\s+system\s+(\d+) \d{4}-\d{2}-\d{2} \d{2}:\d{2} #{File.basename(path)}$/
apk_file = PLATFORM_CURRENT_RELEASE_APK
if !File.exists?(apk_file) || $1.to_i == File.size(apk_file)
return true
else
return false
end
end
sdcard_path = "/mnt/asec/#{package_name}#{i}/pkg.apk"
o = `adb shell ls -l #{sdcard_path}`.chomp
if o =~ /^-r-xr-xr-x system\s+root\s+(\d+) \d{4}-\d{2}-\d{2} \d{2}:\d{2} #{File.basename(sdcard_path)}$/
apk_file = PLATFORM_CURRENT_RELEASE_APK
if !File.exists?(apk_file) || $1.to_i == File.size(apk_file)
return true
else
return false
end
end
end
return nil
end
end
desc 'Download the latest jruby-jars snapshot'
task :get_jruby_jars_snapshots do
download_host = 'lafo.ssw.uni-linz.ac.at'
index = Net::HTTP.get(download_host, "/graalvm/")
current_gems = index.scan(/jruby-jars-.*?.gem/).uniq
current_gems.each do |gem|
print "Downloading #{gem}: \r"
uri = URI("http://#{download_host}/graalvm/#{gem}")
done = 0
body = ''
Net::HTTP.new(uri.host, uri.port).request_get(uri.path) do |response|
length = response['Content-Length'].to_i
response.read_body do |fragment|
body << fragment
done += fragment.length
progress = (done * 100) / length
print "Downloading #{gem}: #{done / 1024}/#{length / 1024}KB #{progress}%\r"
end
puts
end
File.open(gem, 'wb') { |f| f << body }
end
end
task '.travis.yml' do
puts "Regenerating #{'.travis.yml'}"
source = File.read('.travis.yml')
matrix = ''
allow_failures = ''
['L', 19, 17, 16, 15].each.with_index do |api, i|
n = i
[['CURRENT', [nil]], ['FROM_GEM', [:MASTER, :STABLE]], ['STANDALONE', [:MASTER, :STABLE, '1.7.16', '1.7.13']]].each do |platform, versions|
versions.each do |v|
n = (n % 5) + 1
line = " - ANDROID_TARGET=#{api} RUBOTO_PLATFORM=#{platform.ljust(10)} TEST_PART=#{n}of5#{" JRUBY_JARS_VERSION=#{v}" if v}\n"
matrix << line
if (platform == 'STANDALONE' && v == :MASTER) ||
# FIXME(uwe): Remove when Android L is released
api == 'L' ||
# FIXME(uwe): Remove when master and stable branches are downloadable and green.
v == :MASTER || v == :STABLE
# EMXiF
allow_failures << line.gsub('-', '- env:')
end
end
end
matrix << "\n"
end
matrix << " - ANDROID_TARGET=10 RUBOTO_PLATFORM=CURRENT\n"
matrix_str = " matrix:\n#{matrix}\n"
allow_failures_str = <<EOF
allow_failures:
# Current master is failing: https://github.com/jruby/jruby/issues/1741
# Current JRuby 1.7.x gem is failing. Why?
#{allow_failures}
EOF
File.write('.travis.yml', source.
sub(/^ matrix:.*?(?=^matrix:)/m, matrix_str).
sub(/^ allow_failures:.*?(?=^script:)/m, allow_failures_str))
end