fastlane 2.69.0.beta.20171212010004 → 2.69.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/deliver/lib/assets/DeliverfileDefault.swift +13 -0
- data/deliver/lib/deliver/commands_generator.rb +2 -1
- data/deliver/lib/deliver/options.rb +8 -3
- data/deliver/lib/deliver/setup.rb +19 -3
- data/fastlane/lib/assets/AppfileTemplate.swift +8 -0
- data/fastlane/lib/assets/DefaultFastfileTemplate.swift +72 -0
- data/fastlane/lib/fastlane.rb +6 -0
- data/fastlane/lib/fastlane/.DS_Store +0 -0
- data/fastlane/lib/fastlane/action.rb +13 -0
- data/fastlane/lib/fastlane/actions/adb.rb +4 -0
- data/fastlane/lib/fastlane/actions/appium.rb +2 -0
- data/fastlane/lib/fastlane/actions/bundle_install.rb +2 -0
- data/fastlane/lib/fastlane/actions/carthage.rb +12 -24
- data/fastlane/lib/fastlane/actions/changelog_from_git_commits.rb +5 -0
- data/fastlane/lib/fastlane/actions/cocoapods.rb +2 -1
- data/fastlane/lib/fastlane/actions/commit_github_file.rb +4 -0
- data/fastlane/lib/fastlane/actions/environment_variable.rb +73 -0
- data/fastlane/lib/fastlane/actions/get_version_number.rb +4 -4
- data/fastlane/lib/fastlane/actions/increment_build_number.rb +4 -0
- data/fastlane/lib/fastlane/actions/increment_version_number.rb +4 -0
- data/fastlane/lib/fastlane/actions/is_ci.rb +4 -0
- data/fastlane/lib/fastlane/actions/last_git_commit.rb +4 -0
- data/fastlane/lib/fastlane/actions/last_git_tag.rb +4 -0
- data/fastlane/lib/fastlane/actions/latest_testflight_build_number.rb +4 -0
- data/fastlane/lib/fastlane/actions/modify_services.rb +1 -0
- data/fastlane/lib/fastlane/actions/number_of_commits.rb +4 -0
- data/fastlane/lib/fastlane/actions/podio_item.rb +1 -0
- data/fastlane/lib/fastlane/actions/prompt.rb +4 -0
- data/fastlane/lib/fastlane/actions/read_podspec.rb +4 -0
- data/fastlane/lib/fastlane/actions/register_device.rb +4 -0
- data/fastlane/lib/fastlane/actions/register_devices.rb +1 -0
- data/fastlane/lib/fastlane/actions/rocket.rb +4 -0
- data/fastlane/lib/fastlane/actions/set_github_release.rb +4 -0
- data/fastlane/lib/fastlane/actions/sh.rb +5 -0
- data/fastlane/lib/fastlane/actions/slather.rb +14 -0
- data/fastlane/lib/fastlane/actions/update_urban_airship_configuration.rb +1 -0
- data/fastlane/lib/fastlane/actions/xcode_install.rb +4 -0
- data/fastlane/lib/fastlane/actions/xcode_server_get_assets.rb +4 -0
- data/fastlane/lib/fastlane/actions/zip.rb +4 -0
- data/fastlane/lib/fastlane/boolean.rb +5 -0
- data/fastlane/lib/fastlane/command_line_handler.rb +6 -1
- data/fastlane/lib/fastlane/commands_generator.rb +40 -1
- data/fastlane/lib/fastlane/fast_file.rb +5 -1
- data/fastlane/lib/fastlane/lane_list.rb +67 -4
- data/fastlane/lib/fastlane/lane_manager.rb +3 -69
- data/fastlane/lib/fastlane/lane_manager_base.rb +124 -0
- data/fastlane/lib/fastlane/runner.rb +2 -2
- data/fastlane/lib/fastlane/server/command.rb +70 -0
- data/fastlane/lib/fastlane/server/command_executor.rb +9 -0
- data/fastlane/lib/fastlane/server/socket_server.rb +212 -0
- data/fastlane/lib/fastlane/server/socket_server_action_command_executor.rb +100 -0
- data/fastlane/lib/fastlane/setup/setup.rb +7 -2
- data/fastlane/lib/fastlane/setup/setup_ios.rb +72 -15
- data/fastlane/lib/fastlane/swift_fastlane_api_generator.rb +265 -0
- data/fastlane/lib/fastlane/swift_fastlane_function.rb +342 -0
- data/fastlane/lib/fastlane/swift_lane_manager.rb +246 -0
- data/fastlane/lib/fastlane/tools.rb +13 -0
- data/fastlane/lib/fastlane/version.rb +1 -1
- data/fastlane_core/lib/fastlane_core.rb +3 -0
- data/fastlane_core/lib/fastlane_core/analytics/action_launch_context.rb +6 -3
- data/fastlane_core/lib/fastlane_core/analytics/analytics_session.rb +7 -0
- data/fastlane_core/lib/fastlane_core/configuration/commander_generator.rb +13 -0
- data/fastlane_core/lib/fastlane_core/configuration/config_item.rb +33 -2
- data/fastlane_core/lib/fastlane_core/fastlane_folder.rb +32 -0
- data/gym/lib/assets/GymfileTemplate.swift +13 -0
- data/gym/lib/gym/commands_generator.rb +14 -2
- data/gym/lib/gym/generators/build_command_generator.rb +2 -2
- data/gym/lib/gym/options.rb +11 -0
- data/match/lib/assets/MatchfileTemplate.swift +9 -0
- data/match/lib/match/commands_generator.rb +9 -3
- data/match/lib/match/options.rb +1 -0
- data/match/lib/match/setup.rb +6 -2
- data/precheck/lib/.DS_Store +0 -0
- data/precheck/lib/assets/PrecheckfileTemplate +1 -1
- data/precheck/lib/assets/PrecheckfileTemplate.swift +19 -0
- data/precheck/lib/precheck/commands_generator.rb +13 -2
- data/scan/lib/assets/ScanfileTemplate.swift +13 -0
- data/scan/lib/scan/commands_generator.rb +14 -2
- data/scan/lib/scan/options.rb +6 -0
- data/screengrab/lib/assets/ScreengrabfileTemplate.swift +15 -0
- data/screengrab/lib/screengrab/commands_generator.rb +2 -1
- data/screengrab/lib/screengrab/setup.rb +9 -3
- data/snapshot/lib/assets/SnapfileTemplate.swift +41 -0
- data/snapshot/lib/snapshot/commands_generator.rb +2 -1
- data/snapshot/lib/snapshot/setup.rb +9 -3
- data/spaceship/lib/spaceship/client.rb +4 -1
- metadata +38 -16
@@ -1,5 +1,7 @@
|
|
1
|
+
require_relative 'lane_manager_base.rb'
|
2
|
+
|
1
3
|
module Fastlane
|
2
|
-
class LaneManager
|
4
|
+
class LaneManager < LaneManagerBase
|
3
5
|
# @param platform The name of the platform to execute
|
4
6
|
# @param lane_name The name of the lane to execute
|
5
7
|
# @param parameters [Hash] The parameters passed from the command line to the lane
|
@@ -171,73 +173,5 @@ module Fastlane
|
|
171
173
|
UI.user_error! "Run `fastlane` the next time you need to build, test or release your app 🚀"
|
172
174
|
end
|
173
175
|
end
|
174
|
-
|
175
|
-
# @param env_cl_param [String] an optional list of dotenv environment names separated by commas, without space
|
176
|
-
def self.load_dot_env(env_cl_param)
|
177
|
-
base_path = find_dotenv_directory
|
178
|
-
|
179
|
-
return unless base_path
|
180
|
-
|
181
|
-
load_dot_envs_from(env_cl_param, base_path)
|
182
|
-
end
|
183
|
-
|
184
|
-
# finds the first directory of [fastlane, its parent] containing dotenv files
|
185
|
-
def self.find_dotenv_directory
|
186
|
-
path = FastlaneCore::FastlaneFolder.path
|
187
|
-
search_paths = [path]
|
188
|
-
search_paths << path + "/.." unless path.nil?
|
189
|
-
search_paths.compact!
|
190
|
-
search_paths.find do |dir|
|
191
|
-
Dir.glob(File.join(dir, '*.env*'), File::FNM_DOTMATCH).count > 0
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# loads the dotenvs. First the .env and .env.default and
|
196
|
-
# then override with all speficied extra environments
|
197
|
-
def self.load_dot_envs_from(env_cl_param, base_path)
|
198
|
-
require 'dotenv'
|
199
|
-
|
200
|
-
# Making sure the default '.env' and '.env.default' get loaded
|
201
|
-
env_file = File.join(base_path, '.env')
|
202
|
-
env_default_file = File.join(base_path, '.env.default')
|
203
|
-
Dotenv.load(env_file, env_default_file)
|
204
|
-
|
205
|
-
return unless env_cl_param
|
206
|
-
|
207
|
-
Actions.lane_context[Actions::SharedValues::ENVIRONMENT] = env_cl_param
|
208
|
-
|
209
|
-
# multiple envs?
|
210
|
-
envs = env_cl_param.split(",")
|
211
|
-
|
212
|
-
# Loads .env file for the environment(s) passed in through options
|
213
|
-
envs.each do |env|
|
214
|
-
env_file = File.join(base_path, ".env.#{env}")
|
215
|
-
UI.success "Loading from '#{env_file}'"
|
216
|
-
Dotenv.overload(env_file)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
private_class_method :find_dotenv_directory, :load_dot_envs_from
|
221
|
-
|
222
|
-
def self.print_lane_context
|
223
|
-
return if Actions.lane_context.empty?
|
224
|
-
|
225
|
-
if FastlaneCore::Globals.verbose?
|
226
|
-
UI.important 'Lane Context:'.yellow
|
227
|
-
UI.message Actions.lane_context
|
228
|
-
return
|
229
|
-
end
|
230
|
-
|
231
|
-
# Print a nice table unless in FastlaneCore::Globals.verbose? mode
|
232
|
-
rows = Actions.lane_context.collect do |key, content|
|
233
|
-
[key, content.to_s]
|
234
|
-
end
|
235
|
-
|
236
|
-
require 'terminal-table'
|
237
|
-
puts Terminal::Table.new({
|
238
|
-
title: "Lane Context".yellow,
|
239
|
-
rows: FastlaneCore::PrintTable.transform_output(rows)
|
240
|
-
})
|
241
|
-
end
|
242
176
|
end
|
243
177
|
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Fastlane
|
2
|
+
# Base class for all LaneManager classes
|
3
|
+
# Takes care of all common things like printing the lane description tables and loading .env files
|
4
|
+
class LaneManagerBase
|
5
|
+
def self.skip_docs?
|
6
|
+
Helper.test? || FastlaneCore::Env.truthy?("FASTLANE_SKIP_DOCS")
|
7
|
+
end
|
8
|
+
|
9
|
+
# All the finishing up that needs to be done
|
10
|
+
def self.finish_fastlane(ff, duration, error)
|
11
|
+
# Sometimes we don't have a fastfile because we're using Fastfile.swift
|
12
|
+
unless ff.nil?
|
13
|
+
ff.runner.did_finish
|
14
|
+
end
|
15
|
+
|
16
|
+
# Finished with all the lanes
|
17
|
+
Fastlane::JUnitGenerator.generate(Fastlane::Actions.executed_actions)
|
18
|
+
print_table(Fastlane::Actions.executed_actions)
|
19
|
+
|
20
|
+
Fastlane::PluginUpdateManager.show_update_status
|
21
|
+
|
22
|
+
if error
|
23
|
+
UI.error 'fastlane finished with errors'
|
24
|
+
raise error
|
25
|
+
elsif duration > 5
|
26
|
+
UI.success "fastlane.tools just saved you #{duration} minutes! 🎉"
|
27
|
+
else
|
28
|
+
UI.success 'fastlane.tools finished successfully 🎉'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Print a table as summary of the executed actions
|
33
|
+
def self.print_table(actions)
|
34
|
+
return if actions.count == 0
|
35
|
+
|
36
|
+
require 'terminal-table'
|
37
|
+
|
38
|
+
rows = []
|
39
|
+
actions.each_with_index do |current, i|
|
40
|
+
is_error_step = !current[:error].to_s.empty?
|
41
|
+
|
42
|
+
name = current[:name][0..60]
|
43
|
+
name = name.red if is_error_step
|
44
|
+
index = i + 1
|
45
|
+
index = "💥" if is_error_step
|
46
|
+
rows << [index, name, current[:time].to_i]
|
47
|
+
end
|
48
|
+
|
49
|
+
puts ""
|
50
|
+
puts Terminal::Table.new(
|
51
|
+
title: "fastlane summary".green,
|
52
|
+
headings: ["Step", "Action", "Time (in s)"],
|
53
|
+
rows: FastlaneCore::PrintTable.transform_output(rows)
|
54
|
+
)
|
55
|
+
puts ""
|
56
|
+
end
|
57
|
+
|
58
|
+
# @param env_cl_param [String] an optional list of dotenv environment names separated by commas, without space
|
59
|
+
def self.load_dot_env(env_cl_param)
|
60
|
+
base_path = find_dotenv_directory
|
61
|
+
|
62
|
+
return unless base_path
|
63
|
+
|
64
|
+
load_dot_envs_from(env_cl_param, base_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
# finds the first directory of [fastlane, its parent] containing dotenv files
|
68
|
+
def self.find_dotenv_directory
|
69
|
+
path = FastlaneCore::FastlaneFolder.path
|
70
|
+
search_paths = [path]
|
71
|
+
search_paths << path + "/.." unless path.nil?
|
72
|
+
search_paths.compact!
|
73
|
+
search_paths.find do |dir|
|
74
|
+
Dir.glob(File.join(dir, '*.env*'), File::FNM_DOTMATCH).count > 0
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# loads the dotenvs. First the .env and .env.default and
|
79
|
+
# then override with all speficied extra environments
|
80
|
+
def self.load_dot_envs_from(env_cl_param, base_path)
|
81
|
+
require 'dotenv'
|
82
|
+
|
83
|
+
# Making sure the default '.env' and '.env.default' get loaded
|
84
|
+
env_file = File.join(base_path, '.env')
|
85
|
+
env_default_file = File.join(base_path, '.env.default')
|
86
|
+
Dotenv.load(env_file, env_default_file)
|
87
|
+
|
88
|
+
return unless env_cl_param
|
89
|
+
|
90
|
+
Actions.lane_context[Actions::SharedValues::ENVIRONMENT] = env_cl_param
|
91
|
+
|
92
|
+
# multiple envs?
|
93
|
+
envs = env_cl_param.split(",")
|
94
|
+
|
95
|
+
# Loads .env file for the environment(s) passed in through options
|
96
|
+
envs.each do |env|
|
97
|
+
env_file = File.join(base_path, ".env.#{env}")
|
98
|
+
UI.success "Loading from '#{env_file}'"
|
99
|
+
Dotenv.overload(env_file)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.print_lane_context
|
104
|
+
return if Actions.lane_context.empty?
|
105
|
+
|
106
|
+
if FastlaneCore::Globals.verbose?
|
107
|
+
UI.important 'Lane Context:'.yellow
|
108
|
+
UI.message Actions.lane_context
|
109
|
+
return
|
110
|
+
end
|
111
|
+
|
112
|
+
# Print a nice table unless in FastlaneCore::Globals.verbose? mode
|
113
|
+
rows = Actions.lane_context.collect do |key, content|
|
114
|
+
[key, content.to_s]
|
115
|
+
end
|
116
|
+
|
117
|
+
require 'terminal-table'
|
118
|
+
puts Terminal::Table.new({
|
119
|
+
title: "Lane Context".yellow,
|
120
|
+
rows: FastlaneCore::PrintTable.transform_output(rows)
|
121
|
+
})
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -212,7 +212,7 @@ module Fastlane
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
|
-
def execute_action(method_sym, class_ref, arguments, custom_dir: nil, from_action: false)
|
215
|
+
def execute_action(method_sym, class_ref, arguments, custom_dir: nil, from_action: false, configuration_language: nil)
|
216
216
|
if custom_dir.nil?
|
217
217
|
custom_dir ||= "." if Helper.test?
|
218
218
|
custom_dir ||= ".."
|
@@ -221,7 +221,7 @@ module Fastlane
|
|
221
221
|
verify_supported_os(method_sym, class_ref)
|
222
222
|
|
223
223
|
begin
|
224
|
-
launch_context = FastlaneCore::ActionLaunchContext.context_for_action_name(method_sym.to_s, args: ARGV)
|
224
|
+
launch_context = FastlaneCore::ActionLaunchContext.context_for_action_name(method_sym.to_s, configuration_language: configuration_language, args: ARGV)
|
225
225
|
FastlaneCore.session.action_launched(launch_context: launch_context)
|
226
226
|
|
227
227
|
Dir.chdir(custom_dir) do # go up from the fastlane folder, to the project folder
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
class Argument
|
5
|
+
def initialize(json: nil)
|
6
|
+
@name = json['name']
|
7
|
+
@value = json['value']
|
8
|
+
@value_type = json['value_type']
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_named
|
12
|
+
return @name.to_s.length > 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def inspect
|
16
|
+
if is_named
|
17
|
+
return "named argument: #{name}, value: #{value}, type: #{value_type}"
|
18
|
+
else
|
19
|
+
return "unnamed argument value: #{value}, type: #{value_type}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :name
|
24
|
+
attr_reader :value
|
25
|
+
attr_reader :value_type
|
26
|
+
end
|
27
|
+
|
28
|
+
class Command
|
29
|
+
def initialize(json: nil)
|
30
|
+
command_json = JSON.parse(json)
|
31
|
+
@method_name = command_json['methodName']
|
32
|
+
@class_name = command_json['className']
|
33
|
+
@command_id = command_json['commandID']
|
34
|
+
|
35
|
+
args_json = command_json['args'] ||= []
|
36
|
+
@args = args_json.map do |arg|
|
37
|
+
Argument.new(json: arg)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def target_class
|
42
|
+
unless class_name
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
|
46
|
+
return Fastlane::Actions.const_get(class_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def is_class_method_command
|
50
|
+
return class_name.to_s.length > 0
|
51
|
+
end
|
52
|
+
|
53
|
+
attr_reader :command_id # always present
|
54
|
+
attr_reader :args # always present
|
55
|
+
attr_reader :method_name # always present
|
56
|
+
attr_reader :class_name # only present when executing a class-method
|
57
|
+
end
|
58
|
+
|
59
|
+
class CommandReturn
|
60
|
+
attr_reader :return_value
|
61
|
+
attr_reader :return_value_type
|
62
|
+
attr_reader :closure_argument_value
|
63
|
+
|
64
|
+
def initialize(return_value: nil, return_value_type: nil, closure_argument_value: nil)
|
65
|
+
@return_value = return_value
|
66
|
+
@closure_argument_value = closure_argument_value
|
67
|
+
@return_value_type = return_value_type
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,212 @@
|
|
1
|
+
require 'fastlane/server/command.rb'
|
2
|
+
require 'fastlane/server/command_executor.rb'
|
3
|
+
require 'socket'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Fastlane
|
7
|
+
class SocketServer
|
8
|
+
attr_accessor :command_executor
|
9
|
+
attr_accessor :return_value_processor
|
10
|
+
|
11
|
+
def initialize(
|
12
|
+
command_executor: nil,
|
13
|
+
return_value_processor: nil,
|
14
|
+
connection_timeout: 5,
|
15
|
+
stay_alive: false
|
16
|
+
)
|
17
|
+
if return_value_processor.nil?
|
18
|
+
return_value_processor = JSONReturnValueProcessor.new
|
19
|
+
end
|
20
|
+
|
21
|
+
@command_executor = command_executor
|
22
|
+
@return_value_processor = return_value_processor
|
23
|
+
@connection_timeout = connection_timeout.to_i
|
24
|
+
@stay_alive = stay_alive
|
25
|
+
end
|
26
|
+
|
27
|
+
# This is the public API, don't call anything else
|
28
|
+
def start
|
29
|
+
while listen
|
30
|
+
# Loop for-ev-er
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def receive_and_process_commands
|
37
|
+
# We'll break out of the infinite loop somehow, either error or 'done' message
|
38
|
+
ended_loop_due_to_error = true
|
39
|
+
|
40
|
+
loop do # No idea how many commands are coming, so we loop until an error or the done command is sent
|
41
|
+
str = nil
|
42
|
+
|
43
|
+
begin
|
44
|
+
str = @client.recv(1_048_576) # 1024 * 1024
|
45
|
+
rescue Errno::ECONNRESET => e
|
46
|
+
UI.verbose(e)
|
47
|
+
break
|
48
|
+
end
|
49
|
+
|
50
|
+
if str == 'done'
|
51
|
+
time = Time.new
|
52
|
+
UI.verbose("[#{time.usec}]: received done signal, shutting down")
|
53
|
+
ended_loop_due_to_error = false
|
54
|
+
break
|
55
|
+
end
|
56
|
+
response_json = process_command(command_json: str)
|
57
|
+
|
58
|
+
time = Time.new
|
59
|
+
UI.verbose("[#{time.usec}]: sending #{response_json}")
|
60
|
+
begin
|
61
|
+
@client.puts(response_json) # Send some json to the client
|
62
|
+
rescue Errno::EPIPE => e
|
63
|
+
UI.verbose(e)
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
return handle_disconnect(error: ended_loop_due_to_error)
|
69
|
+
end
|
70
|
+
|
71
|
+
def listen
|
72
|
+
@server = TCPServer.open('localhost', 2000) # Socket to listen on port 2000
|
73
|
+
UI.message("Waiting for #{@connection_timeout} seconds for a connection from FastlaneRunner")
|
74
|
+
|
75
|
+
# set thread local to ready so we can check it
|
76
|
+
Thread.current[:ready] = true
|
77
|
+
@client = nil
|
78
|
+
begin
|
79
|
+
Timeout.timeout(@connection_timeout) do
|
80
|
+
@client = @server.accept # Wait for a client to connect
|
81
|
+
end
|
82
|
+
rescue Timeout::Error
|
83
|
+
UI.user_error!("fastlane failed to receive a connection from the FastlaneRunner binary after #{@connection_timeout} seconds, shutting down")
|
84
|
+
rescue StandardError => e
|
85
|
+
UI.user_error!("Something went wrong while waiting for a connection from the FastlaneRunner binary, shutting down\n#{e}")
|
86
|
+
end
|
87
|
+
UI.message("Client connected")
|
88
|
+
|
89
|
+
receive_and_process_commands
|
90
|
+
end
|
91
|
+
|
92
|
+
def handle_disconnect(error: false)
|
93
|
+
UI.important("Client disconnected, or a pipe broke") if error
|
94
|
+
if @stay_alive
|
95
|
+
UI.important("stay_alive is set to true, restarting server")
|
96
|
+
# clean up before restart
|
97
|
+
@client.close
|
98
|
+
@client = nil
|
99
|
+
|
100
|
+
@server.close
|
101
|
+
@server = nil
|
102
|
+
return true # Restart server
|
103
|
+
end
|
104
|
+
return false # Don't restart server
|
105
|
+
end
|
106
|
+
|
107
|
+
def process_command(command_json: nil)
|
108
|
+
time = Time.new
|
109
|
+
UI.verbose("[#{time.usec}]: received command:#{command_json}")
|
110
|
+
return execute_command(command_json: command_json)
|
111
|
+
end
|
112
|
+
|
113
|
+
def execute_command(command_json: nil)
|
114
|
+
command = Command.new(json: command_json)
|
115
|
+
command_return = @command_executor.execute(command: command, target_object: nil)
|
116
|
+
## probably need to just return Strings, or ready_for_next with object isn't String
|
117
|
+
return_object = command_return.return_value
|
118
|
+
return_value_type = command_return.return_value_type
|
119
|
+
closure_arg = command_return.closure_argument_value
|
120
|
+
|
121
|
+
return_object = return_value_processor.prepare_object(
|
122
|
+
return_value: return_object,
|
123
|
+
return_value_type: return_value_type
|
124
|
+
)
|
125
|
+
|
126
|
+
if closure_arg.nil?
|
127
|
+
closure_arg = closure_arg.to_s
|
128
|
+
else
|
129
|
+
closure_arg = return_value_processor.prepare_object(
|
130
|
+
return_value: closure_arg,
|
131
|
+
return_value_type: :string # always assume string for closure error_callback
|
132
|
+
)
|
133
|
+
closure_arg = ', "closure_argument_value": ' + closure_arg
|
134
|
+
end
|
135
|
+
|
136
|
+
return '{"payload":{"status":"ready_for_next", "return_object":' + return_object + closure_arg + '}}'
|
137
|
+
rescue StandardError => e
|
138
|
+
exception_array = []
|
139
|
+
exception_array << "#{e.class}:"
|
140
|
+
exception_array << e.backtrace
|
141
|
+
|
142
|
+
while e.respond_to?("cause") && (e = e.cause)
|
143
|
+
exception_array << "cause: #{e.class}"
|
144
|
+
exception_array << backtrace
|
145
|
+
end
|
146
|
+
return "{\"payload\":{\"status\":\"failure\",\"failure_information\":#{exception_array.flatten}}}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
class JSONReturnValueProcessor
|
151
|
+
def prepare_object(return_value: nil, return_value_type: nil)
|
152
|
+
case return_value_type
|
153
|
+
when nil
|
154
|
+
UI.verbose("return_value_type is nil value: #{return_value}")
|
155
|
+
return process_value_as_string(return_value: return_value)
|
156
|
+
when :string
|
157
|
+
return process_value_as_string(return_value: return_value)
|
158
|
+
when :int
|
159
|
+
return process_value_as_int(return_value: return_value)
|
160
|
+
when :bool
|
161
|
+
return process_value_as_bool(return_value: return_value)
|
162
|
+
when :array_of_strings
|
163
|
+
return process_value_as_array_of_strings(return_value: return_value)
|
164
|
+
when :hash_of_strings
|
165
|
+
return process_value_as_hash_of_strings(return_value: return_value)
|
166
|
+
else
|
167
|
+
UI.verbose("Unknown return type defined: #{return_value_type} for value: #{return_value}")
|
168
|
+
return process_value_as_string(return_value: return_value)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def process_value_as_string(return_value: nil)
|
173
|
+
if return_value.nil?
|
174
|
+
return_value = ""
|
175
|
+
end
|
176
|
+
|
177
|
+
return JSON.generate(return_value.to_s)
|
178
|
+
end
|
179
|
+
|
180
|
+
def process_value_as_array_of_strings(return_value: nil)
|
181
|
+
if return_value.nil?
|
182
|
+
return_value = []
|
183
|
+
end
|
184
|
+
|
185
|
+
return JSON.generate(return_value)
|
186
|
+
end
|
187
|
+
|
188
|
+
def process_value_as_hash_of_strings(return_value: nil)
|
189
|
+
if return_value.nil?
|
190
|
+
return_value = {}
|
191
|
+
end
|
192
|
+
|
193
|
+
return JSON.generate(return_value)
|
194
|
+
end
|
195
|
+
|
196
|
+
def process_value_as_bool(return_value: nil)
|
197
|
+
if return_value.nil?
|
198
|
+
return_value = false
|
199
|
+
end
|
200
|
+
|
201
|
+
return JSON.generate(return_value)
|
202
|
+
end
|
203
|
+
|
204
|
+
def process_value_as_int(return_value: nil)
|
205
|
+
if return_value.nil?
|
206
|
+
return_value = 0
|
207
|
+
end
|
208
|
+
|
209
|
+
return JSON.generate(return_value)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|