38f57ae400
Some Jenkins plugins depend on other plugins, and their configuration section is a mix of both plugins. For Jenkins Job Builder, that means reusing one component directly from another one. Driving the generation of XML markup is the job of Base._dispatch. Unfortunately, components do not have access to their module object, and even if their could, _dispatch would still be a non-public method. Refactor Base._dispatch into ModuleRegistry.dispatch, which can be used from any place where the parser is available. Base and ModuleRegistry are extended so that the registry can discover which entry point must be used for each module, if appropriate. ModuleRegistry.dispatch signature can be simplified by dropping component_list_type parameter. Change-Id: Ie9d090817d0c2d464745b5634a22d3cea6a47ab1 Reviewed-on: https://review.openstack.org/26051 Reviewed-by: James E. Blair <corvus@inaugust.com> Reviewed-by: Jeremy Stanley <fungi@yuggoth.org> Approved: Clark Boylan <clark.boylan@gmail.com> Reviewed-by: Clark Boylan <clark.boylan@gmail.com> Tested-by: Jenkins
85 lines
2.9 KiB
Python
85 lines
2.9 KiB
Python
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
# Base class for a jenkins_jobs module
|
|
|
|
import xml.etree.ElementTree as XML
|
|
|
|
|
|
def add_nonblank_xml_subelement(parent, tag, value):
|
|
"""
|
|
Adds an XML SubElement with the name tag to parent if value is a non-empty
|
|
string
|
|
"""
|
|
if value is not None and value != '':
|
|
XML.SubElement(parent, tag).text = value
|
|
|
|
|
|
class Base(object):
|
|
"""
|
|
A base class for a Jenkins Job Builder Module.
|
|
|
|
The module is initialized before any YAML is parsed.
|
|
|
|
:arg ModuleRegistry registry: the global module registry.
|
|
"""
|
|
|
|
#: The sequence number for the module. Modules are invoked in the
|
|
#: order of their sequence number in order to produce consistently
|
|
#: ordered XML output.
|
|
sequence = 10
|
|
|
|
#: The component type for components of this module. This will be
|
|
#: used to look for macros (they are defined singularly, and should
|
|
#: not be plural).
|
|
#: Set both component_type and component_list_type to None if module
|
|
#: doesn't have components.
|
|
component_type = None
|
|
|
|
#: The component list type will be used to look up possible
|
|
#: implementations of the component type via entry points (entry
|
|
#: points provide a list of components, so it should be plural).
|
|
#: Set both component_type and component_list_type to None if module
|
|
#: doesn't have components.
|
|
component_list_type = None
|
|
|
|
def __init__(self, registry):
|
|
self.registry = registry
|
|
|
|
def handle_data(self, parser):
|
|
"""This method is called before any XML is generated. By
|
|
overriding this method, the module may manipulate the YAML
|
|
data structure on the parser however it likes before any XML
|
|
is generated. If it has changed the data structure at all, it
|
|
must return ``True``, otherwise, it must return ``False``.
|
|
|
|
:arg YAMLParser parser: the global YAML Parser
|
|
:rtype: boolean
|
|
"""
|
|
|
|
return False
|
|
|
|
def gen_xml(self, parser, xml_parent, data):
|
|
"""Update the XML element tree based on YAML data. Override
|
|
this method to add elements to the XML output. Create new
|
|
Element objects and add them to the xml_parent. The YAML data
|
|
structure must not be modified.
|
|
|
|
:arg YAMLParser parser: the global YAML Parser
|
|
:arg Element xml_parent: the parent XML element
|
|
:arg dict data: the YAML data structure
|
|
"""
|
|
|
|
pass
|