Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 12a52e0

Browse files
authored
Merge pull request #20 from BranchMetrics/rexml
Replace nokogiri with REXML
2 parents 3cd5af6 + 9cd8e7a commit 12a52e0

File tree

4 files changed

+54
-57
lines changed

4 files changed

+54
-57
lines changed

Gemfile.lock

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ PATH
22
remote: .
33
specs:
44
fastlane-plugin-branch (0.1.0)
5-
nokogiri
65
plist
76
xcodeproj
87

98
GEM
109
remote: https://rubygems.org/
1110
specs:
1211
CFPropertyList (2.3.5)
13-
activesupport (4.2.8)
12+
activesupport (4.2.9)
1413
i18n (~> 0.7)
1514
minitest (~> 5.1)
1615
thread_safe (~> 0.3, >= 0.3.4)
@@ -20,10 +19,10 @@ GEM
2019
ast (2.3.0)
2120
babosa (1.0.2)
2221
claide (1.0.2)
23-
cocoapods (1.2.1)
22+
cocoapods (1.3.0)
2423
activesupport (>= 4.0.2, < 5)
25-
claide (>= 1.0.1, < 2.0)
26-
cocoapods-core (= 1.2.1)
24+
claide (>= 1.0.2, < 2.0)
25+
cocoapods-core (= 1.3.0)
2726
cocoapods-deintegrate (>= 1.0.1, < 2.0)
2827
cocoapods-downloader (>= 1.1.3, < 2.0)
2928
cocoapods-plugins (>= 1.0.0, < 2.0)
@@ -38,9 +37,9 @@ GEM
3837
molinillo (~> 0.5.7)
3938
nap (~> 1.0)
4039
ruby-macho (~> 1.1)
41-
xcodeproj (>= 1.4.4, < 2.0)
42-
cocoapods-core (1.2.1)
43-
activesupport (>= 4.0.2, < 5)
40+
xcodeproj (>= 1.5.1, < 2.0)
41+
cocoapods-core (1.3.0)
42+
activesupport (>= 4.0.2, < 6)
4443
fuzzy_match (~> 2.0.4)
4544
nap (~> 1.0)
4645
cocoapods-deintegrate (1.0.1)
@@ -56,7 +55,7 @@ GEM
5655
coderay (1.1.1)
5756
colored (1.2)
5857
colored2 (3.1.2)
59-
commander-fastlane (4.4.4)
58+
commander-fastlane (4.4.5)
6059
highline (~> 1.7.2)
6160
declarative (0.0.9)
6261
declarative-option (0.1.0)
@@ -66,28 +65,28 @@ GEM
6665
unf (>= 0.0.5, < 1.0.0)
6766
dotenv (2.2.1)
6867
escape (0.0.4)
69-
excon (0.57.0)
70-
faraday (0.12.1)
68+
excon (0.58.0)
69+
faraday (0.12.2)
7170
multipart-post (>= 1.2, < 3)
7271
faraday-cookie_jar (0.0.6)
7372
faraday (>= 0.7.4)
7473
http-cookie (~> 1.0.0)
75-
faraday_middleware (0.11.0.1)
74+
faraday_middleware (0.12.2)
7675
faraday (>= 0.7.4, < 1.0)
7776
fastimage (2.1.0)
78-
fastlane (2.39.2)
77+
fastlane (2.50.1)
7978
CFPropertyList (>= 2.3, < 3.0.0)
8079
addressable (>= 2.3, < 3.0.0)
8180
babosa (>= 1.0.2, < 2.0.0)
8281
bundler (>= 1.12.0, < 2.0.0)
8382
colored
84-
commander-fastlane (>= 4.4.0, < 5.0.0)
83+
commander-fastlane (>= 4.4.5, < 5.0.0)
8584
dotenv (>= 2.1.1, < 3.0.0)
8685
excon (>= 0.45.0, < 1.0.0)
8786
faraday (~> 0.9)
8887
faraday-cookie_jar (~> 0.0.6)
8988
faraday_middleware (~> 0.9)
90-
fastimage (>= 1.6)
89+
fastimage (>= 2.1.0, < 3.0.0)
9190
gh_inspector (>= 1.0.1, < 2.0.0)
9291
google-api-client (>= 0.12.0, < 0.13.0)
9392
highline (>= 1.7.2, < 2.0.0)
@@ -117,8 +116,8 @@ GEM
117116
mime-types (~> 3.0)
118117
representable (~> 3.0)
119118
retriable (>= 2.0, < 4.0)
120-
googleauth (0.5.1)
121-
faraday (~> 0.9)
119+
googleauth (0.5.3)
120+
faraday (~> 0.12)
122121
jwt (~> 1.4)
123122
logging (~> 2.0)
124123
memoist (~> 0.12)
@@ -129,32 +128,29 @@ GEM
129128
http-cookie (1.0.3)
130129
domain_name (~> 0.5)
131130
httpclient (2.8.3)
132-
i18n (0.8.4)
131+
i18n (0.8.6)
133132
json (2.1.0)
134133
jwt (1.5.6)
135134
little-plugger (1.1.4)
136135
logging (2.2.2)
137136
little-plugger (~> 1.1)
138137
multi_json (~> 1.10)
139-
memoist (0.15.0)
138+
memoist (0.16.0)
140139
method_source (0.8.2)
141140
mime-types (3.1)
142141
mime-types-data (~> 3.2015)
143142
mime-types-data (3.2016.0521)
144143
mini_magick (4.5.1)
145-
mini_portile2 (2.2.0)
146-
minitest (5.10.2)
144+
minitest (5.10.3)
147145
molinillo (0.5.7)
148146
multi_json (1.12.1)
149147
multi_xml (0.6.0)
150148
multipart-post (2.0.0)
151149
nanaimo (0.2.3)
152150
nap (1.1.0)
153151
netrc (0.7.8)
154-
nokogiri (1.8.0)
155-
mini_portile2 (~> 2.2.0)
156152
os (0.9.6)
157-
parallel (1.11.2)
153+
parallel (1.12.0)
158154
parser (2.4.0.0)
159155
ast (~> 2.2)
160156
plist (3.3.0)
@@ -171,7 +167,7 @@ GEM
171167
declarative (< 0.1.0)
172168
declarative-option (< 0.2.0)
173169
uber (< 0.2.0)
174-
retriable (3.0.2)
170+
retriable (3.1.1)
175171
rouge (2.0.7)
176172
rspec (3.6.0)
177173
rspec-core (~> 3.6.0)
@@ -221,9 +217,9 @@ GEM
221217
unf (0.1.4)
222218
unf_ext
223219
unf_ext (0.0.7.4)
224-
unicode-display_width (1.2.1)
220+
unicode-display_width (1.3.0)
225221
word_wrap (1.0.0)
226-
xcodeproj (1.5.0)
222+
xcodeproj (1.5.1)
227223
CFPropertyList (~> 2.3.3)
228224
claide (>= 1.0.2, < 2.0)
229225
colored2 (~> 3.1)
@@ -249,4 +245,4 @@ DEPENDENCIES
249245
simplecov
250246

251247
BUNDLED WITH
252-
1.15.1
248+
1.15.3

fastlane-plugin-branch.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
1818
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1919
spec.require_paths = ['lib']
2020

21-
spec.add_dependency 'nokogiri'
2221
spec.add_dependency 'plist'
2322
spec.add_dependency 'xcodeproj'
2423

lib/fastlane/plugin/branch/actions/setup_branch_action.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require "rexml/document"
12
require "xcodeproj"
23

34
module Fastlane
@@ -51,7 +52,7 @@ def self.run(params)
5152
if params[:android_project_path] || params[:android_manifest_path]
5253
# :android_manifest_path overrides :android_project_path
5354
manifest_path = params[:android_manifest_path] || "#{params[:android_project_path]}/app/src/main/AndroidManifest.xml"
54-
manifest = File.open(manifest_path) { |f| Nokogiri::XML f }
55+
manifest = File.open(manifest_path) { |f| REXML::Document.new f }
5556

5657
helper.add_keys_to_android_manifest manifest, keys
5758
# :activity_name and :uri_scheme may be nil. :remove_existing_domains defaults to false
@@ -62,7 +63,7 @@ def self.run(params)
6263
params[:remove_existing_domains]
6364

6465
File.open(manifest_path, "w") do |f|
65-
manifest.write_xml_to f, ident: 4
66+
manifest.write f, 4
6667
end
6768

6869
helper.add_change File.expand_path(manifest_path, Bundler.root)

lib/fastlane/plugin/branch/helper/android_helper.rb

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "nokogiri"
2-
31
module Fastlane
42
module Helper
53
module AndroidHelper
@@ -11,18 +9,18 @@ def add_keys_to_android_manifest(manifest, keys)
119
# TODO: Work on all XML/AndroidManifest formatting
1210

1311
def add_metadata_to_manifest(manifest, key, value)
14-
element = manifest.at_css "manifest > application > meta-data[android|name=\"#{key}\"]"
12+
element = manifest.elements["//manifest/application/meta-data[@android:name=\"#{key}\"]"]
1513
if element.nil?
16-
application = manifest.at_css "manifest application"
17-
application.add_child " <meta-data android:name=\"#{key}\" android:value=\"#{value}\" />\n"
14+
application = manifest.elements["//manifest/application"]
15+
application.add_element "meta-data", "android:name" => key, "android:value" => value
1816
else
19-
element["android:value"] = value
17+
element.attributes["android:value"] = value
2018
end
2119
end
2220

2321
def add_intent_filters_to_android_manifest(manifest, domains, uri_scheme, activity_name, remove_existing)
2422
if activity_name
25-
activity = manifest.at_css "manifest > application > activity[android|name=\"#{activity_name}\""
23+
activity = manifest.elements["//manifest/application/activity[@android:name=\"#{activity_name}\""]
2624
else
2725
activity = find_activity manifest
2826
end
@@ -39,46 +37,49 @@ def add_intent_filters_to_android_manifest(manifest, domains, uri_scheme, activi
3937
def find_activity(manifest)
4038
# try to infer the right activity
4139
# look for the first singleTask
42-
single_task_activity = manifest.at_css "manifest > application > activity[android|launchMode=\"singleTask\"]"
40+
single_task_activity = manifest.elements["//manifest/application/activity[@android:launchMode=\"singleTask\"]"]
4341
return single_task_activity if single_task_activity
4442

4543
# no singleTask activities. Take the first Activity
4644
# TODO: Add singleTask?
47-
manifest.at_css "manifest > application > activity"
45+
manifest.elements["//manifest/application/activity"]
4846
end
4947

5048
def add_intent_filter_to_activity(activity, domains, uri_scheme)
5149
# Add a single intent-filter with autoVerify and a data element for each domain and the optional uri_scheme
52-
intent_filter = <<-EOF
50+
intent_filter = REXML::Element.new "intent-filter"
51+
intent_filter.attributes["android:autoverify"] = true
52+
intent_filter.add_element "action", "android:name" => "android.intent.action.VIEW"
53+
intent_filter.add_element "category", "android:name" => "android.intent.category.DEFAULT"
54+
intent_filter.add_element "category", "android:name" => "android.intent.category.BROWSABLE"
55+
intent_filter.elements << uri_scheme_data_element(uri_scheme) unless uri_scheme.nil?
56+
app_link_data_elements(domains).each { |e| intent_filter.elements << e }
5357

54-
<intent-filter android:autoverify="true">
55-
<action android:name="android.intent.action.VIEW"/>
56-
<category android:name="android.intent.category.DEFAULT"/>
57-
<category android:name="android.intent.category.BROWSABLE"/>
58-
#{app_link_data_elements domains}
59-
#{uri_scheme_data_element uri_scheme}
60-
</intent-filter>
61-
EOF
62-
intent_filter += " " * 8
63-
activity.add_child intent_filter
58+
activity.add_element intent_filter
6459
end
6560

6661
def remove_existing_domains(activity)
6762
# Find all intent-filters that include a data element with android:scheme
6863
# TODO: Can this be done with a single css/at_css call?
69-
activity.css("intent-filter").each do |filter|
70-
filter.remove if filter.at_css "data[android|scheme]"
64+
activity.elements.each("//manifest//intent-filter") do |filter|
65+
filter.remove if filter.elements["data[@android:scheme]"]
7166
end
7267
end
7368

7469
def app_link_data_elements(domains)
75-
domains.map { |d| "<data android:scheme=\"https\" android:host=\"#{d}\"/>" }.join("\n" + " " * 16)
70+
domains.map do |domain|
71+
element = REXML::Element.new "data"
72+
element.attributes["android:scheme"] = "https"
73+
element.attributes["android:host"] = domain
74+
element
75+
end
7676
end
7777

7878
def uri_scheme_data_element(uri_scheme)
79-
return "" if uri_scheme.nil?
80-
81-
"<data android:scheme=\"#{uri_scheme}\" android:host=\"open\"/>"
79+
element = REXML::Element.new "data"
80+
element.attributes["android:scheme"] = uri_scheme
81+
element.attributes["android:host"] = "open"
82+
element
8283
end
8384
end
8485
end

0 commit comments

Comments
 (0)