Bug 1074258 - Expand entities at build time when copying strings.xml in Gradle. r=me
authorNick Alexander <nalexander@mozilla.com>
Wed, 17 Feb 2016 17:16:51 -0800
changeset 284561 f4abd2bf1fd3330e787cfb29cbea6775fd1fb713
parent 284560 66195b41545d726273105901c7471a62a962ea6c
child 284562 3b35f0a98eba9f1c9be7d793650b3d5bec6c8fdb
push id17669
push usernalexander@mozilla.com
push dateThu, 18 Feb 2016 03:31:11 +0000
treeherderfx-team@f4abd2bf1fd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
Bug 1074258 - Expand entities at build time when copying strings.xml in Gradle. r=me DONTBUILD NPOTB Android Studio (and IntelliJ) does not correctly handle &entity; definitions in Android strings.xml files. Strings with entities (in Fennec, all of them) are rendered in the IDE as blank. This patch expands the entities when copying for use by Gradle, improving the IDE integration. MozReview-Commit-ID: 2T6CzoKc7v8
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -228,19 +228,35 @@ task syncAssetsFromDistDir(type: Sync, d
 task syncPreprocessedCode(type: Sync, dependsOn: rootProject.generateCodeAndResources) {
+// The localization system uses the moz.build preprocessor to interpolate a .dtd
+// file of XML entity definitions into an XML file of elements referencing those
+// entities.  (Each locale produces its own .dtd file, backstopped by the en-US
+// .dtd file in tree.)  Android Studio (and IntelliJ) don't handle these inline
+// entities smoothly.  This filter merely expands the entities in place, making
+// them appear properly throughout the IDE.
+class ExpandXMLEntitiesFilter extends FilterReader {
+    ExpandXMLEntitiesFilter(Reader input) {
+        // Extremely inefficient, but whatever.
+        super(new StringReader(groovy.xml.XmlUtil.serialize(new XmlParser(false, false, true).parse(input))))
+    }
 task syncPreprocessedResources(type: Sync, dependsOn: rootProject.generateCodeAndResources) {
+    filesMatching('**/strings.xml') {
+        filter(ExpandXMLEntitiesFilter)
+    }
 // The omnijar inputs are listed as resource directory inputs to a dummy JAR.
 // That arrangement labels them nicely in IntelliJ.  See the comment in the
 // :omnijar project for more context.
 task buildOmnijar(type:Exec) {