Skip to content

Commit fa19d34

Browse files
committed
Implement add_ignore_attr on an_localise_libs
1 parent d4d1dd9 commit fa19d34

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/actions/android/an_localize_libs_action.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ def self.details
3333

3434
def self.available_options
3535
libs_hash_description = <<~KEYS
36-
- `:library`: The library display name
37-
- `:strings_path`: The path to the `strings.xml` file of the library
38-
- `:exclusions`: An optional `Array` of string keys to exclude from merging
36+
- `:library`: The library display name.
37+
- `:strings_path`: The path to the `strings.xml` file of the library.
38+
- `:exclusions`: An optional `Array` of string keys to exclude from merging.
3939
- `:source_id`: An optional `String` which will be added as the `a8c-src-lib` XML attribute
4040
to strings coming from this library, to help identify their source in the merged file.
41+
- `:add_ignore_attr`: If set to true, will add `tools:ignore="UnusedResources"` to merged strings.
4142
KEYS
4243
[
4344
FastlaneCore::ConfigItem.new(key: :app_strings_path,

lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,20 @@ def self.skip_string_by_exclusion_list(library, string_name)
3333
end
3434
end
3535

36+
# Adds the appropriate XML attributes to an XML `<string>` node according to library configuration
37+
def self.add_xml_attributes!(string_node, library)
38+
if library[:add_ignore_attr] == true
39+
existing_ignores = (string_node['tools:ignore'] || '').split(',')
40+
existing_ignores.append('UnusedResources') unless existing_ignores.include?('UnusedResources')
41+
string_node['tools:ignore'] = existing_ignores.join(',')
42+
end
43+
string_node[LIB_SOURCE_XML_ATTR] = library[:source_id] unless library[:source_id].nil?
44+
end
45+
3646
# Merge string_line into main_string
3747
def self.merge_string(main_strings, library, string_line)
3848
string_name = string_line.attr('name')
3949
string_content = string_line.content
40-
lib_src_id = library[:source_id]
4150

4251
# Skip strings in the exclusions list
4352
return :skipped if skip_string_by_exclusion_list(library, string_name)
@@ -61,14 +70,14 @@ def self.merge_string(main_strings, library, string_line)
6170
else
6271
# It has the tools:ignore flag, so update the content without touching the other attributes
6372
this_string.content = string_content
64-
this_string[LIB_SOURCE_XML_ATTR] = lib_src_id unless lib_src_id.nil?
73+
add_xml_attributes!(this_string, library)
6574
return result
6675
end
6776
end
6877
end
6978

7079
# String not found, or removed because needing update and not in the exclusion list: add to the main file
71-
string_line[LIB_SOURCE_XML_ATTR] = lib_src_id unless lib_src_id.nil?
80+
add_xml_attributes!(string_line, library)
7281
main_strings.xpath('//string').last().add_next_sibling("\n#{' ' * 4}#{string_line.to_xml().strip}")
7382
return result
7483
end
@@ -103,8 +112,14 @@ def self.verify_string(main_strings, library, string_line)
103112
# @param [Hash] library Hash describing the library to merge. The Hash should contain the following keys:
104113
# - `:library`: The human readable name of the library, used to display in console messages
105114
# - `:strings_path`: The path to the strings.xml file of the library to merge into the main one
106-
# - `:exclusions`: An array of strings keys to exclude during merge. Any of those keys from the library's `strings.xml` will be skipped and won't be merged into the main one.
115+
# - `:exclusions`: An array of strings keys to exclude during merge. Any of those keys from the
116+
# library's `strings.xml` will be skipped and won't be merged into the main one.
117+
# - `:source_id`: An optional `String` which will be added as the `a8c-src-lib` XML attribute
118+
# to strings coming from this library, to help identify their source in the merged file.
119+
# - `:add_ignore_attr`: If set to true, will add `tools:ignore="UnusedResources"` to merged strings.
120+
#
107121
# @return [Boolean] True if at least one string from the library has been added to (or has updated) the main strings file.
122+
#
108123
def self.merge_lib(main, library)
109124
UI.message("Merging #{library[:library]} strings into #{main}")
110125
main_strings = File.open(main) { |f| Nokogiri::XML(f, nil, Encoding::UTF_8.to_s) }

0 commit comments

Comments
 (0)