Пример #1
0
    def _setup_encoding(self, encoding):
        """
        Uses a specific encoding.

        :param encoding: encoding to use
        :type encoding: string
        """
        dict_ = {
                'groupId': 'org.apache.maven.plugins',
                'artifactId': 'maven-site-plugin',
                'version': '2.3',
                'configuration': {
                    'outputEncoding': encoding}}
        e = SubElement(self.plugin_tree, 'plugin')
        dict2tree(e, dict_)
Пример #2
0
    def add_repository(self, url, identifier=None):
        """
        Adds a repository to the POM.

        The identifier of the repository will be equal to
        the url by default.

        :param url: the URL of the repository
        :type url: string
        """
        if url in self.repositories:
            return

        if not identifier:
            identifier = url

        e = SubElement(self.repository_tree, 'repository')
        dict2tree(e, {'url': url, 'id': identifier})

        self.repositories.add(url)
Пример #3
0
    def add_dependency(self, dep):
        """
        Adds a given dependency to the POM.

        :param dep: the dependency
        :type dep: :class:`MavenDependency`
        """
        if dep in self.dependencies:
            return

        if dep.repo:
            self.add_repository(dep.repo)

        clean_dep = dict((k, v) for k, v in dep.__dict__.items() if k in
                MavenDependency.POM_ATTRIBS and v)

        e = SubElement(self.dependency_tree, 'dependency')
        dict2tree(e, clean_dep)

        self.dependencies.add(dep)
Пример #4
0
    def __init__(self, encoding='UTF-8', **kwargs):
        if not set(kwargs.keys()).issuperset(self.__class__.REQUIRED_ATTRIBS):
            raise POMError(', '.join(self.__class__.REQUIRED_ATTRIBS) +
                    ' are required keywords')
        self.repositories = set()
        self.dependencies = set()

        self.root = Element('project')
        self.tree = ElementTree(self.root)
        self.dependency_tree = SubElement(self.root, 'dependencies')
        self.repository_tree = SubElement(self.root, 'repositories')
        self.build_tree = SubElement(self.root, 'build')
        self.plugin_tree = SubElement(self.build_tree, 'plugins')

        attribs = POM.ATTRIBS.copy()
        attribs.update(kwargs)
        dict2tree(self.root, attribs)

        if encoding:
            self._setup_encoding(encoding)