From b9fcb0f81411cecebe4f9252910b634423ac6006 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 21 Sep 2017 12:37:37 +0200 Subject: update ics-openvpn: cleanup build.gradle --- app/build.gradle | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'app') diff --git a/app/build.gradle b/app/build.gradle index af44b9a2..97ce9c35 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -141,34 +141,25 @@ task copyIcsOpenVPNImages( type: Copy ) { } into '.' } -//TODO: avoid code duplication // thanks to http://pleac.sourceforge.net/pleac_groovy/fileaccess.html task removeDuplicatedStrings() { println "removeDuplicatedStrings" new File('.').eachFileRecurse { - if(it.name.equals('strings.xml')) { - def ics_openvpn_file = file(it.absolutePath.replace('strings.xml', 'strings-icsopenvpn.xml')) - if(ics_openvpn_file.exists()) { - def ics_openvpn_strings_names = (new XmlParser()).parse(ics_openvpn_file) - def current_file = it - - ics_openvpn_strings_names.string.each { - processFileInplace(current_file) { text -> - text.replaceAll('.*name=\"' + it.attribute('name') + '\".*(\n)*.*string>.*\n+', '') - } - } - } - } else if (it.name.equals('plurals.xml')) { - def ics_openvpn_file = file(it.absolutePath.replace('plurals.xml', 'plurals-icsopenvpn.xml')) - if(ics_openvpn_file.exists()) { - def ics_openvpn_strings_names = (new XmlParser()).parse(ics_openvpn_file) - def current_file = it - - ics_openvpn_strings_names.string.each { - processFileInplace(current_file) { text -> - text.replaceAll('.*name=\"' + it.attribute('name') + '\".*(\n)*.*string>.*\n+', '') - } - } + if(it.name.equals('strings.xml') || it.name.equals('plurals.xml')) { + replaceDuplicatesForSource(it, it.name.substring(0, it.name.lastIndexOf('.'))) + } + } +} + +def replaceDuplicatesForSource(File it, String type) { + def ics_openvpn_file = file(it.absolutePath.replace(type+'.xml', type+'-icsopenvpn.xml')) + if(ics_openvpn_file.exists()) { + def ics_openvpn_strings_names = (new XmlParser()).parse(ics_openvpn_file) + def current_file = it + + ics_openvpn_strings_names.string.each { + processFileInplace(current_file) { text -> + text.replaceAll('.*name=\"' + it.attribute('name') + '\".*(\n)*.*string>.*\n+', '') } } } -- cgit v1.2.3