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 id30007
push usercbook@mozilla.com
push dateThu, 18 Feb 2016 10:57:40 +0000
treeherdermozilla-central@3b35f0a98eba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1074258
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
mobile/android/app/build.gradle
--- 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) {
     into("${project.buildDir}/generated/source/preprocessed_code")
     from("${topobjdir}/mobile/android/base/generated/preprocessed")
 }
 
+// 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) {
     into("${project.buildDir}/generated/source/preprocessed_resources")
     from("${topobjdir}/mobile/android/base/res")
+    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.
 evaluationDependsOn(':omnijar')
 
 task buildOmnijar(type:Exec) {