-
Notifications
You must be signed in to change notification settings - Fork 14
/
get_value_from_build.rb
81 lines (73 loc) · 2.75 KB
/
get_value_from_build.rb
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
require 'fileutils'
module Fastlane
module Actions
class GetValueFromBuildAction < Action
def self.run(params)
app_project_dir ||= params[:app_project_dir]
regex = Regexp.new(/(?<key>#{params[:key]}\s+)(?<left>[\'\"]?)(?<value>[a-zA-Z0-9\.\_]*)(?<right>[\'\"]?)(?<comment>.*)/)
flavor = params[:flavor]
flavorSpecified = !(flavor.nil? or flavor.empty?)
value = ""
found = false
flavorFound = false
productFlavorsSection = false
Dir.glob("#{app_project_dir}/build.gradle") do |path|
UI.verbose("path: #{path}")
UI.verbose("absolute_path: #{File.expand_path(path)}")
begin
File.open(path, 'r') do |file|
file.each_line do |line|
if flavorSpecified and !productFlavorsSection
unless line.include? "productFlavors"
next
end
productFlavorsSection = true
end
if flavorSpecified and !flavorFound
unless line.include? " #{flavor} "
next
end
flavorFound = true
end
unless line.match(regex) and !found
next
end
key, left, value, right, comment = line.match(regex).captures
break
end
file.close
end
end
end
return value
end
#####################################################
# @!group Documentation
#####################################################
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :app_project_dir,
env_name: "ANDROID_VERSIONING_APP_PROJECT_DIR",
description: "The path to the application source folder in the Android project (default: android/app)",
optional: true,
type: String,
default_value: "android/app"),
FastlaneCore::ConfigItem.new(key: :flavor,
env_name: "ANDROID_VERSIONING_FLAVOR",
description: "The product flavor name (optional)",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :key,
description: "The property key",
type: String)
]
end
def self.authors
["Manabu OHTAKE"]
end
def self.is_supported?(platform)
platform == :android
end
end
end
end