Bug 975504 - Add filtered_resources to AndroidEclipseProjectData. r=bnicholson
authorNick Alexander <nalexander@mozilla.com>
Tue, 25 Feb 2014 15:59:31 -0800
changeset 170572 6d99d4df5e4fa96b107ef7597db6fdbf8f389f17
parent 170494 2a97a8e98f0412e1eb2dc74b98ea02343781869f
child 170573 cb23ee71ead6fb7e70b66668c113b4004cc59168
push id26292
push userttaubert@mozilla.com
push dateWed, 26 Feb 2014 11:03:49 +0000
treeherdermozilla-central@0bfea5715ed4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs975504
milestone30.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 975504 - Add filtered_resources to AndroidEclipseProjectData. r=bnicholson
mobile/android/base/moz.build
python/mozbuild/mozbuild/backend/android_eclipse.py
python/mozbuild/mozbuild/backend/templates/android_eclipse/.project
python/mozbuild/mozbuild/frontend/data.py
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -497,16 +497,24 @@ generated.res = OBJDIR + '/res'
 
 branding = add_android_eclipse_library_project('FennecResourcesBranding')
 branding.package_name = 'org.mozilla.fennec.resources.branding'
 branding.res = TOPSRCDIR + '/' + CONFIG['MOZ_BRANDING_DIRECTORY'] + '/res'
 
 main = add_android_eclipse_project('Fennec', OBJDIR + '/AndroidManifest.xml')
 main.package_name = 'org.mozilla.gecko'
 
+# These values were extracted from an existing Eclipse project.  Use
+# Project > Resource > Resource Filters and inspect the resulting
+# .project file to modify this list.
+main.filtered_resources += [
+    '1.0-projectRelativePath-matches-false-false-*org/mozilla/gecko/resources/**',
+    '1.0-projectRelativePath-matches-false-false-*org/mozilla/gecko/tests/**',
+]
+
 main.recursive_make_targets += ['.aapt.deps'] # Captures dependencies on Android manifest and all resources.
 main.recursive_make_targets += [OBJDIR + '/generated/' + f for f in mgjar.generated_sources]
 main.recursive_make_targets += [OBJDIR + '/generated/' + f for f in gbjar.generated_sources]
 
 main.included_projects += ['../' + generated.name, '../' + branding.name]
 main.referenced_projects += [generated.name, branding.name]
 main.extra_jars += [CONFIG['ANDROID_COMPAT_LIB']]
 main.assets = TOPOBJDIR + '/dist/fennec/assets'
--- a/python/mozbuild/mozbuild/backend/android_eclipse.py
+++ b/python/mozbuild/mozbuild/backend/android_eclipse.py
@@ -1,17 +1,19 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import unicode_literals
 
 import itertools
 import os
+import time
 import types
+import xml.dom.minidom as minidom
 import xml.etree.ElementTree as ET
 
 from mozpack.copier import FileCopier
 from mozpack.files import (FileFinder, PreprocessedFile)
 from mozpack.manifests import InstallManifest
 import mozpack.path as mozpath
 
 from .common import CommonBackend
@@ -19,16 +21,24 @@ from ..frontend.data import (
     AndroidEclipseProjectData,
     SandboxDerived,
     SandboxWrapped,
 )
 from ..makeutil import Makefile
 from ..util import ensureParentDir
 
 
+def pretty_print(element):
+    """Return a pretty-printed XML string for an Element.
+    """
+    s = ET.tostring(element, 'utf-8')
+    # minidom wraps element in a Document node; firstChild strips it.
+    return minidom.parseString(s).firstChild.toprettyxml(indent='  ')
+
+
 class AndroidEclipseBackend(CommonBackend):
     """Backend that generates Android Eclipse project files.
     """
 
     def _init(self):
         CommonBackend._init(self)
 
         def detailed(summary):
@@ -109,16 +119,47 @@ class AndroidEclipseBackend(CommonBacken
         <classpathentry exported="true" kind="lib" path="/Users/nalexander/Mozilla/gecko-dev/build/mobile/robocop/robotium-solo-4.3.1.jar"/>
         """
         e = ET.Element('classpathentry')
         e.set('kind', 'lib')
         e.set('exported', 'true')
         e.set('path', name)
         return e
 
+    def _Element_for_filtered_resources(self, filtered_resources):
+        """Turn a list of filtered resource arguments like
+        ['1.0-projectRelativePath-matches-false-false-*org/mozilla/gecko/resources/**']
+        into an XML Element, like:
+        <filteredResources>
+          <filter>
+            <id>1393009101322</id>
+            <name></name>
+            <type>30</type>
+            <matcher>
+              <id>org.eclipse.ui.ide.multiFilter</id>
+              <arguments>1.0-projectRelativePath-matches-false-false-*org/mozilla/gecko/resources/**</arguments>
+            </matcher>
+          </filter>
+        </filteredResources>
+
+        The id is random; the values are magic."""
+
+        id = int(1000 * time.time())
+        filteredResources = ET.Element('filteredResources')
+        for arg in sorted(filtered_resources):
+            e = ET.SubElement(filteredResources, 'filter')
+            ET.SubElement(e, 'id').text = str(id)
+            id += 1
+            ET.SubElement(e, 'name')
+            ET.SubElement(e, 'type').text = '30' # It's magic!
+            matcher = ET.SubElement(e, 'matcher')
+            ET.SubElement(matcher, 'id').text = 'org.eclipse.ui.ide.multiFilter'
+            ET.SubElement(matcher, 'arguments').text = str(arg)
+        return filteredResources
+
     def _manifest_for_project(self, srcdir, project):
         manifest = InstallManifest()
 
         if project.manifest:
             manifest.add_copy(mozpath.join(srcdir, project.manifest), 'AndroidManifest.xml')
 
         if project.res:
             manifest.add_symlink(mozpath.join(srcdir, project.res), 'res')
@@ -187,16 +228,21 @@ class AndroidEclipseBackend(CommonBacken
         defines['IDE_CLASSPATH_ENTRIES'] = '\n'.join('\t' + cpe for cpe in classpathentries)
         defines['IDE_RECURSIVE_MAKE_TARGETS'] = ' '.join(sorted(data.recursive_make_targets))
         # Like android.library=true
         defines['IDE_PROJECT_LIBRARY_SETTING'] = 'android.library=true' if data.is_library else ''
         # Like android.library.reference.1=FennecBrandingResources
         defines['IDE_PROJECT_LIBRARY_REFERENCES'] = '\n'.join(
             'android.library.reference.%s=%s' % (i + 1, ref)
             for i, ref in enumerate(sorted(data.included_projects)))
+        if data.filtered_resources:
+            filteredResources = self._Element_for_filtered_resources(data.filtered_resources)
+            defines['IDE_PROJECT_FILTERED_RESOURCES'] = pretty_print(filteredResources).strip()
+        else:
+            defines['IDE_PROJECT_FILTERED_RESOURCES'] = ''
 
         copier = FileCopier()
         finder = FileFinder(template_directory)
         for input_filename, f in itertools.chain(finder.find('**'), finder.find('.**')):
             if input_filename == 'AndroidManifest.xml' and not data.is_library:
                 # Main projects supply their own manifests.
                 continue
             copier.add(input_filename, PreprocessedFile(
--- a/python/mozbuild/mozbuild/backend/templates/android_eclipse/.project
+++ b/python/mozbuild/mozbuild/backend/templates/android_eclipse/.project
@@ -44,9 +44,10 @@
 				</dictionary>
 			</arguments>
 		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
 	</natures>
+@IDE_PROJECT_FILTERED_RESOURCES@
 </projectDescription>
--- a/python/mozbuild/mozbuild/frontend/data.py
+++ b/python/mozbuild/mozbuild/frontend/data.py
@@ -592,30 +592,32 @@ class AndroidEclipseProjectData(object):
         'assets',
         'libs',
         'manifest',
         'recursive_make_targets',
         'extra_jars',
         'included_projects',
         'referenced_projects',
         '_classpathentries',
+        'filtered_resources',
     )
 
     def __init__(self, name):
         self.name = name
         self.is_library = False
         self.manifest = None
         self.res = None
         self.assets = None
         self.libs = []
         self.recursive_make_targets = []
         self.extra_jars = []
         self.included_projects = []
         self.referenced_projects = []
         self._classpathentries = []
+        self.filtered_resources = []
 
     def add_classpathentry(self, path, srcdir, dstdir, exclude_patterns=[], ignore_warnings=False):
         cpe = ClassPathEntry()
         cpe.srcdir = srcdir
         cpe.dstdir = dstdir
         cpe.path = path
         cpe.exclude_patterns = list(exclude_patterns)
         cpe.ignore_warnings = ignore_warnings