Bug 975504 - Add filtered_resources to AndroidEclipseProjectData. r=bnicholson

This commit is contained in:
Nick Alexander 2014-02-25 15:59:31 -08:00
parent 3f77308423
commit 2c78fbb251
4 changed files with 57 additions and 0 deletions

View File

@ -502,6 +502,14 @@ 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]

View File

@ -6,7 +6,9 @@ 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
@ -24,6 +26,14 @@ 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.
"""
@ -114,6 +124,37 @@ class AndroidEclipseBackend(CommonBackend):
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()
@ -192,6 +233,11 @@ class AndroidEclipseBackend(CommonBackend):
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)

View File

@ -49,4 +49,5 @@
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
@IDE_PROJECT_FILTERED_RESOURCES@
</projectDescription>

View File

@ -597,6 +597,7 @@ class AndroidEclipseProjectData(object):
'included_projects',
'referenced_projects',
'_classpathentries',
'filtered_resources',
)
def __init__(self, name):
@ -611,6 +612,7 @@ class AndroidEclipseProjectData(object):
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()