示例#1
0
    def test_find_text_ignoring_namespaces(self):
        test_doc = self.get_test_loc('xmlutils/ant-jai-1.7.0.pom')
        expr = "/*[local-name()='project']/*[local-name()='modelVersion']"
        handler = lambda xdoc: xmlutils.find_text(xdoc, expr)
        test = xmlutils.parse(test_doc, handler)
        assert ['4.0.0'] == test

        expr2 = xmlutils.namespace_unaware("/project/modelVersion")
        handler2 = lambda xdoc: xmlutils.find_text(xdoc, expr2)
        test = xmlutils.parse(test_doc, handler2)
        assert ['4.0.0'] == test
示例#2
0
def extract_pom_data(xdoc, fields=MAVEN_FIELDS):
    """
    Extract POM data from an etree document using a `fields` mapping of field
    name -> xpath.
    Return a mapping of field name -> [values].
    """
    pom_data = {}
    props = get_properties(xdoc)

    for name, xpath in fields:
        values = xmlutils.find_text(xdoc, xpath)
        if values:
            pass
            # logger.debug('processing name: {name}, xpath: {xpath}'.format(**locals()))
            # logger.debug(' found: {values}'.format(**locals()))
        resolved = [resolve_properties(val , props)for val in values]

        if resolved:
            logger.debug(' extract_pom_data: found: {resolved}'.format(**locals()))
        # FIXME: this is grossly incorrect!
        pom_data[name] = resolved or []

    # logger.debug(' found: {pom_data}'.format(**locals()))
    pom_data = inherit_from_parent(pom_data)
    # logger.debug(' inherited: {pom_data}'.format(**locals()))
    return pom_data
示例#3
0
def _nuget_handler(xdoc):
    tags = {}
    for tag in nuspec_tags:
        xpath = xmlutils.namespace_unaware('/package/metadata/{}'.format(tag))
        values = xmlutils.find_text(xdoc, xpath)
        if values:
            value = u''.join(values)
            tags[tag] = value and value or None
    return tags
示例#4
0
def _nuget_handler(xdoc):
    tags = {}
    for tag in nuspec_tags:
        xpath = xmlutils.namespace_unaware('/package/metadata/{}'.format(tag))
        values = xmlutils.find_text(xdoc, xpath)
        if values:
            value = u''.join(values)
            tags[tag] = value and value or None
    return tags
示例#5
0
def get_standard_properties(xdoc):
    """
    Given an XML etree `xdoc`, build a dict mapping property keys to their
    values for "standard" maven properties and pom-specific properties. This
    mapping is used later to resolve properties in the values of the document.
    """
    properties = {}
    for name, xpath in STANDARD_MAVEN_PROPERTIES:
        values = xmlutils.find_text(xdoc, xpath)
#         logger.debug('get_standard_properties: with name=%(name)r,  xpath=%(xpath)r found: values=%(values)r' % locals())
        if not values:
            continue
        if name not in properties or not properties[name]:
#             logger.debug('get_standard_properties:  adding name=%(name)r, values=%(values)r' % locals())
            # FIXME: what if we have several times the same property defined?
            properties[name] = ' '.join(values)

    return properties
示例#6
0
 def test_find_text_handler(self):
     test_doc = self.get_test_loc('xmlutils/project.xml')
     handler = lambda xdoc: xmlutils.find_text(xdoc, '/project/shortDescription')
     test = xmlutils.parse(test_doc, handler)
     assert ['Abbot Tests'] == test