briar 0.1.3.rc1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,122 @@
1
+ require_relative 'briar_help'
2
+ require_relative 'briar_dot_xamarin'
3
+ require_relative 'briar_ideviceinstaller'
4
+
5
+ require 'ansi/logger'
6
+ @log = ANSI::Logger.new(STDOUT)
7
+
8
+ def briar_install_gem
9
+ warn_deprecated('0.1.3', 'will be removed')
10
+ puts 'will install briar gem'
11
+ gem_dir = "#{ENV['HOME']}/git/briar"
12
+ unless File.exists?(gem_dir)
13
+ puts "expected gem '#{gem_dir}' - cannot install the briar gem"
14
+ exit 1
15
+ end
16
+ system("cd #{gem_dir}; rake install")
17
+ exit 0
18
+ end
19
+
20
+ def briar_install_calabash_gem
21
+ warn_deprecated('0.1.3', 'will be removed')
22
+ puts 'will install calabash-cucumber gem'
23
+ gem_dir = "#{ENV['HOME']}/git/calabash-ios/calabash-cucumber"
24
+ unless File.exists?(gem_dir)
25
+ puts "expected gem '#{gem_dir}' - cannot install the calabash-cucumber gem"
26
+ exit 1
27
+ end
28
+ system("cd #{gem_dir}; rake install")
29
+ exit 0
30
+ end
31
+
32
+ def calabash_gem_path
33
+ path = ENV['CALABASH_GEM_PATH']
34
+ "#{path}/calabash-cucumber"
35
+ end
36
+
37
+ def expect_calabash_gem_path
38
+ path = calabash_gem_path()
39
+ unless File.exists?(path)
40
+ @log.fatal { "expected calabash-cucumber at '#{path}' - cannot install the calabash server" }
41
+ exit 1
42
+ end
43
+ path
44
+ end
45
+
46
+ def calabash_server_path
47
+ ENV['CALABASH_SERVER_PATH']
48
+ end
49
+
50
+ def expect_calabash_server_path
51
+ path = calabash_server_path
52
+ unless File.exists?(path)
53
+ @log.fatal { "expected calabash-ios server to be in dir '#{path}'" }
54
+ exit 1
55
+ end
56
+ path
57
+ end
58
+
59
+ def briar_install_calabash_server
60
+ puts 'will install calabash-ios server'
61
+ cal_framework = 'calabash.framework'
62
+ unless File.exists?(cal_framework)
63
+ puts "expected '#{cal_framework}' to be in the local directory."
64
+ puts "run this command in the directory that contains '#{cal_framework}'"
65
+ exit 1
66
+ end
67
+
68
+ gem_dir = expect_calabash_gem_path
69
+ server_dir = expect_calabash_server_path
70
+
71
+ version_file = File.read("#{server_dir}/calabash/Classes/FranklyServer/Routes/LPVersionRoute.h")
72
+ tokens = version_file.split(/define kLPCALABASHVERSION/)
73
+ line = tokens[1].split("\n").first
74
+ version = line.tr('^A-Za-z0-9.\-\_', '')
75
+
76
+ puts "building calabash server using 'rake build_server'"
77
+ system("cd #{gem_dir}; rake build_server")
78
+ puts 'remove old cal simulator targets'
79
+ briar_rm(['sim-targets'])
80
+ puts 'copying new framework to ./'
81
+ system("cp #{gem_dir}/staticlib/#{cal_framework}.zip ./")
82
+ puts 'removing old framework'
83
+ system("rm -rf #{cal_framework}")
84
+ puts 'unzipping new framework'
85
+ system("unzip #{cal_framework}.zip")
86
+ puts 'cleaning up'
87
+ system("rm -rf #{cal_framework}.zip")
88
+ puts "installed new server version '#{version}'"
89
+ end
90
+
91
+
92
+ def briar_install(args)
93
+ arg_len = args.length
94
+ if arg_len == 0
95
+ print_install_help
96
+ exit 0
97
+ end
98
+
99
+ if arg_len > 1
100
+ @log.fatal { "briar install takes only one argument but found '#{args}'" }
101
+ print_install_help
102
+ exit 1
103
+ end
104
+
105
+ what = args[0]
106
+
107
+ case what
108
+ when BRIAR_INSTALL_GEM
109
+ briar_install_gem
110
+ when BRIAR_INSTALL_CALABASH_GEM
111
+ briar_install_calabash_gem
112
+ when BRIAR_INSTALL_CALABASH_SERVER
113
+ briar_install_calabash_server
114
+ else
115
+ # install or reinstall application on a device
116
+ briar_device_install(what)
117
+ end
118
+ end
119
+
120
+ def briar_device_install(device)
121
+ ideviceinstaller(device, :reinstall)
122
+ end
@@ -0,0 +1,55 @@
1
+ require_relative './briar_dot_xamarin'
2
+ require 'awesome_print'
3
+ require 'ansi/logger'
4
+
5
+ @log = ANSI::Logger.new(STDOUT)
6
+
7
+
8
+ # opens the most recent calabash report in the default browser
9
+ #
10
+ # ./reports directory must exist
11
+ # if +device+ is non-nil, ./reports/+device+ must exists
12
+ #
13
+ # see cucumber.yml for details about how report paths are created
14
+ def open_report_in_browser(device=nil)
15
+ if device.nil?
16
+ path = File.expand_path('./reports')
17
+ else
18
+ path = File.expand_path("./reports/#{device}")
19
+ end
20
+
21
+ unless File.exists?(path)
22
+ @log.fatal{ 'required directory is missing - see $ briar help cucumber-reports' }
23
+ @log.fatal{ "expected directory at '#{path}'" }
24
+ exit 1
25
+ end
26
+
27
+ open_path = Dir["#{path}/*.html"].sort_by { |file_name|
28
+ File.stat(file_name).mtime
29
+ }.last
30
+
31
+ if open_path.nil?
32
+ @log.warn{ 'there are no reports to open' }
33
+ @log.warn{ "checked in #{path}" }
34
+ exit 0
35
+ end
36
+
37
+ system "open #{open_path}"
38
+ end
39
+
40
+ def briar_report(args)
41
+ arg_len = args.length
42
+ if arg_len == 0
43
+ open_report_in_browser
44
+ exit 0
45
+ end
46
+
47
+ device = args[0]
48
+
49
+ if arg_len > 1
50
+ @log.warn("expected only one argument but found '#{args}'")
51
+ @log.warn('ignoring extra input')
52
+ end
53
+
54
+ open_report_in_browser device
55
+ end
@@ -0,0 +1,84 @@
1
+ require 'find'
2
+ require_relative './briar_sim'
3
+ require 'ansi/logger'
4
+
5
+ @log = ANSI::Logger.new(STDOUT)
6
+
7
+
8
+ def briar_remove_cal_targets
9
+ kill_simulator
10
+ sim_dir="#{ENV['HOME']}/Library/Application Support/iPhone Simulator"
11
+
12
+ # `find "#{sim_dir}" -type d -name '*-cal.app' | sed 's#\(.*\)/.*#\1#' | xargs -I{} rm -rf {}`
13
+ cal_targets = []
14
+ Find.find(sim_dir) do |path|
15
+ if path =~ /.*\-cal.app/
16
+ @log.fatal { "found '#{File.basename(path)}' in '#{File.dirname(path)}'" }
17
+ cal_targets << File.dirname(path)
18
+ Find.prune
19
+ end
20
+ end
21
+
22
+ if cal_targets.empty?
23
+ @log.fatal { "found no *-cal.app targets in '#{sim_dir}'" }
24
+ exit 0
25
+ end
26
+
27
+ cal_targets.each do |path|
28
+ FileUtils.rm_r path
29
+ end
30
+ end
31
+
32
+ def briar_remove_derived_data_dups(opts={})
33
+ default_opts = {:derived_data => ENV['DERIVED_DATA'],
34
+ :prefix => ENV['DERIVED_DATA_PREFIX']}
35
+ opts = default_opts.merge(opts)
36
+
37
+ unexpanded = opts[:derived_data]
38
+ expanded = File.expand_path(unexpanded)
39
+ unless File.exists?(expanded)
40
+ @log.fatal { 'could not find DerivedData directory' }
41
+ @log.fatal { "expected it here '#{unexpanded}'" }
42
+ exit 1
43
+ end
44
+
45
+ prefix = opts[:prefix]
46
+ unless prefix
47
+ @log.fatal { 'requires a directory prefix' }
48
+ exit 1
49
+ end
50
+
51
+ Dir.glob("#{expanded}/#{prefix}-*/").each do |candidate|
52
+ dir_count = Dir["#{candidate}/*/"].length
53
+ if dir_count == 2
54
+ @log.info{ "found #{File.basename(candidate)} with 2 directories - deleting it" }
55
+ FileUtils.rm_r(candidate)
56
+ end
57
+ end
58
+ end
59
+
60
+ def briar_rm(args)
61
+ arg_len = args.count
62
+
63
+ if arg_len == 0
64
+ raise 'expected at least one argument'
65
+ end
66
+
67
+ command = args[0]
68
+ prefix = arg_len == 2 ? args[1] : nil
69
+
70
+ case command
71
+ when 'sim-targets'
72
+ unless prefix.nil?
73
+ @log.warn{ "expected one argument but found '#{args}' - ignoring extra input" }
74
+ end
75
+ briar_remove_cal_targets
76
+ when 'dups'
77
+ opts = prefix.nil? ? {} : {:prefix => prefix}
78
+ briar_remove_derived_data_dups(opts)
79
+ else
80
+ @log.fatal{ "illegal arg '#{command}' - expected #{['sim-targets', 'dups']}" }
81
+ exit 1
82
+ end
83
+ end
84
+
@@ -0,0 +1,107 @@
1
+ require 'awesome_print'
2
+ require 'ansi/logger'
3
+
4
+ @log = ANSI::Logger.new(STDOUT)
5
+
6
+ # returns a verbose simulator description key based on a canonical key
7
+ #
8
+ # using to control which simulator is launched
9
+ def simulator_hash
10
+ {:iphone => 'iPhone Retina (3.5-inch)',
11
+ :iphone_4in => 'iPhone Retina (4-inch)',
12
+ :iphone_4in_64 => 'iPhone Retina (4-inch 64-bit)',
13
+ :ipad => 'iPad',
14
+ :ipad_r => 'iPad Retina',
15
+ :ipad_r_64 => 'iPad Retina (64-bit)'}
16
+ end
17
+
18
+ # returns a canonical key for the current default simulator
19
+ def default_simulated_device
20
+ res = `defaults read com.apple.iphonesimulator "SimulateDevice"`.chomp
21
+ simulator_hash.each { |key, value|
22
+ return key if res.eql?(value)
23
+ }
24
+ raise "could not find '#{res}' in hash values '#{simulator_hash()}'"
25
+ end
26
+
27
+ # kills the simulator if it is running
28
+ #
29
+ # uses Apple Script
30
+ def kill_simulator
31
+ dev_dir = ENV['DEVELOPER_DIR']
32
+ system "/usr/bin/osascript -e 'tell application \"#{dev_dir}/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app\" to quit'"
33
+ end
34
+
35
+ def open_simulator
36
+ dev_dir = ENV['DEVELOPER_DIR']
37
+ system "/usr/bin/osascript -e 'tell application \"#{dev_dir}/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app\" to activate'"
38
+ end
39
+
40
+
41
+ # sets the default simulator using a canonical key
42
+ #
43
+ # :iphone # => 'iPhone Retina (3.5-inch)'
44
+ # :iphone_4in # => 'iPhone Retina (4-inch)'
45
+ # :iphone_4in_64 # => 'iPhone Retina (4-inch 64-bit)'
46
+ # :ipad # => 'iPad'
47
+ # :ipad_r # => 'iPad Retina'
48
+ # :ipad_r_64 # => 'iPad Retina (64-bit)'
49
+ #
50
+ def set_default_simulator(device_key)
51
+ hash = simulator_hash
52
+ unless hash[device_key]
53
+ raise "#{device_key} was not one of '#{hash.keys}'"
54
+ end
55
+
56
+ open_simulator
57
+ current_device = default_simulated_device()
58
+ unless current_device.eql?(device_key)
59
+ value = hash[device_key]
60
+ @log.info{"setting default simulator to '#{value}' using device key '#{device_key}'"}
61
+ `defaults write com.apple.iphonesimulator "SimulateDevice" '"#{value}"'`
62
+ kill_simulator
63
+ end
64
+ open_simulator
65
+ end
66
+
67
+
68
+ def briar_sim(args)
69
+ arg_len = args.length
70
+ if arg_len == 0
71
+ ap simulator_hash
72
+ exit 0
73
+ end
74
+
75
+ if arg_len > 1
76
+ @log.warn{ "expected only 2 args but found '#{args}' - ignoring extra input" }
77
+ end
78
+ if arg_len == 1
79
+ cmd = String.new(args[0])
80
+
81
+ case cmd
82
+ when 'quit'
83
+ @log.info{ 'quiting the simulator' }
84
+ kill_simulator
85
+ when 'open'
86
+ @log.info{ 'making simulator front-most app' }
87
+ open_simulator
88
+ else
89
+ cmd.gsub!('-','_')
90
+ cmd.gsub!(':','')
91
+ sim_version = cmd.to_sym
92
+ hash = simulator_hash
93
+ unless hash[sim_version]
94
+ @log.error{ "cannot convert '#{args[0]}' into a recognized simulator version" }
95
+ @log.error{ "after coercing i found '#{cmd}'" }
96
+ @log.error{ "expected one of '#{hash.keys}'" }
97
+ exit 1
98
+ end
99
+ set_default_simulator sim_version
100
+ end
101
+ end
102
+ end
103
+
104
+
105
+
106
+
107
+
@@ -0,0 +1,108 @@
1
+ require_relative './briar_dot_xamarin'
2
+ require_relative './briar_env'
3
+ require_relative './briar_rm'
4
+ require 'awesome_print'
5
+ require 'ansi/logger'
6
+
7
+ @log = ANSI::Logger.new(STDOUT)
8
+
9
+ # not yet - maybe never
10
+ ##use <tt>rake install</tt> to install a gem at +path_to_gemspec+
11
+ ## returns the version of the gem installed
12
+ #def rake_install_gem(path_to_gemspec)
13
+ #
14
+ # #out = `"cd #{path_to_gemspec}; rake install"`
15
+ #
16
+ # out = nil
17
+ # Dir.chdir(File.expand_path(path_to_gemspec)) do
18
+ # system 'rake install'
19
+ # end
20
+ #
21
+ #
22
+ # #cmd = "cd #{path_to_gemspec} ; rake install"
23
+ # #output = []
24
+ # #IO.popen(cmd).each do |line|
25
+ # # p line.chomp
26
+ # # output << line.chomp
27
+ # #end
28
+ #
29
+ # puts "out = '#{out}'"
30
+ # exit 1
31
+ # tokens = out.split(' ')
32
+ # gem = tokens[0]
33
+ # version = tokens[1]
34
+ # @log.info { "installed #{gem} #{version}" }
35
+ # version
36
+ #end
37
+
38
+ def briar_xtc_submit(device_set, profile, opts={})
39
+ default_opts = {:build_script => ENV['IPA_BUILD_SCRIPT'],
40
+ :ipa => ENV['IPA'],
41
+ :profiles => ENV['XTC_PROFILES'],
42
+ :account => expect_xtc_account()}
43
+
44
+ opts = default_opts.merge(opts)
45
+
46
+ build_script = opts[:build_script]
47
+
48
+ if build_script
49
+ expect_build_script(build_script)
50
+ system "#{build_script}"
51
+ briar_remove_derived_data_dups
52
+ end
53
+
54
+ xtc_gemfile = './xamarin/Gemfile'
55
+
56
+ briar_path = `bundle show briar`.strip
57
+ calabash_path = `bundle show calabash-cucumber`.strip
58
+
59
+ File.open(xtc_gemfile, 'w') { |file|
60
+ file.write("source 'https://rubygems.org'\n")
61
+ file.write("gem 'calabash-cucumber', :path => '#{calabash_path}'\n")
62
+ file.write("gem 'briar', :path => '#{briar_path}'\n")
63
+ file.write("gem 'faker'\n")
64
+ }
65
+
66
+ account = opts[:account]
67
+ api_key = read_api_token(account)
68
+
69
+
70
+ sets = read_device_sets
71
+ if sets[device_set]
72
+ device_set = sets[device_set]
73
+ end
74
+
75
+ profile = 'default' if profile.nil?
76
+
77
+ ipa = File.basename(File.expand_path(expect_ipa(opts[:ipa])))
78
+
79
+ cmd = "bundle exec test-cloud submit #{ipa} #{api_key} -d #{device_set} -c cucumber.yml -p #{profile}"
80
+ puts Rainbow("cd xamarin; #{cmd}").green
81
+ begin
82
+ Dir.chdir('./xamarin') do
83
+ system cmd
84
+ end
85
+ rescue
86
+ # probably useless
87
+ @log.fatal{ 'could not submit job' }
88
+ end
89
+ end
90
+
91
+
92
+ def briar_xtc(args)
93
+ arg_len = args.length
94
+ if arg_len == 0
95
+ ap read_device_sets
96
+ exit 0
97
+ end
98
+
99
+ device_set = args[0]
100
+ profile = arg_len == 1 ? nil : args[1]
101
+
102
+ if arg_len > 2
103
+ @log.warn{ "expected at most 2 args by found '#{args}' - ignoring extra input" }
104
+ end
105
+
106
+ briar_xtc_submit(device_set, profile)
107
+ end
108
+