def groupId(self): """ Effective groupId of the pom Artifact taking into account parent groupId """ gId = POMReader.find(self.__doc, './pom:groupId') if gId is None: gId = POMReader.find(self.__doc, './pom:parent/pom:groupId') if gId is None: raise PomLoadingException("Unable to determine groupId") if len(gId) != 0: raise PomLoadingException("Unexpected child nodes under groupId") return gId.text.strip()
def version(self): """ Effective version of the pom Artifact taking into account parent version """ version = POMReader.find(self.__doc, './pom:version') if version is None: version = POMReader.find(self.__doc, './pom:parent/pom:version') if version is None: raise PomLoadingException("Unable to determine artifact version") if len(version) != 0: raise PomLoadingException("Unexpected child nodes under version") return version.text.strip()
def pluginManagement(self): """ List of plugins from plugin management section """ xmlnodes = POMReader.xpath( self.__doc, './pom:pluginManagement/pom:plugins/pom:plugin') return [Plugin.from_xml_element(x) for x in xmlnodes]
def plugins(self): """ List of artifact's plugins """ xmlnodes = POMReader.xpath(self.__doc, './pom:build/pom:plugins/pom:plugin') return [Plugin.from_xml_element(x) for x in xmlnodes]
def extensions(self): """ List of artifact's extensions """ xmlnodes = POMReader.xpath(self.__doc, './pom:build/pom:extensions/pom:extension') return [Extension.from_xml_element(x) for x in xmlnodes]
def dependencies(self): """ List of artifact's dependencies """ xmlnodes = POMReader.xpath(self.__doc, './pom:dependencies/pom:dependency') return [Dependency.from_xml_element(x) for x in xmlnodes]
def version(self): version = POMReader.find(self.__doc, '/ivy-module/info') if version is not None: try: version = version.attrib["revision"] except KeyError: raise PomLoadingException("Unable to determine version") return version
def artifactId(self): aId = POMReader.find(self.__doc, '/ivy-module/info') if aId is not None: try: aId = aId.attrib["module"] except KeyError: raise PomLoadingException("Unable to determine artifactId") return aId
def parentVersion(self): """ version of the parent artifact or None """ ver = POMReader.find(self.__doc, './pom:parent/pom:version') if ver is None: return None return ver.text.strip()
def parentGroupId(self): """ groupId of the parent artifact or None """ gId = POMReader.find(self.__doc, './pom:parent/pom:groupId') if gId is None: return None return gId.text.strip()
def parentArtifactId(self): """ artifactId of the parent artifact or None """ aId = POMReader.find(self.__doc, './pom:parent/pom:artifactId') if aId is None: return None return aId.text.strip()
def dependencyManagement(self): """ List of dependencies from dependency management section """ xmlnodes = POMReader.xpath( self.__doc, './pom:dependencyManagement/pom:dependencies/pom:dependency') return [Dependency.from_xml_element(x) for x in xmlnodes]
def groupId(self): gId = POMReader.find(self.__doc, '/ivy-module/info') if gId is not None: try: gId = gId.attrib["organisation"] except: raise PomLoadingException("Unable to determine groupId") return gId
def parent(self): aId = POMReader.find(self.__doc, './pom:parent/pom:artifactId') if aId is None: return None aId = aId.text gId = POMReader.find(self.__doc, './pom:parent/pom:groupId') if gId is not None: gId = gId.text ver = POMReader.find(self.__doc, './pom:parent/pom:version') if ver is not None: ver = ver.text relativePath = POMReader.find(self.__doc, './pom:parent/pom:relativePath') if relativePath is not None: relativePath = relativePath.text return ParentPOM(gId, aId, ver, relativePath)
def artifactId(self): """ Effective artifactId of the pom Artifact """ aId = POMReader.find(self.__doc, './pom:artifactId') if aId is None: raise PomLoadingException("Unable to determine artifactId") if len(aId) != 0: raise PomLoadingException( "Unexpected child nodes under artifactId") return aId.text.strip()
def packaging(self): """ Packaging type of artifact or None if unspecified """ packaging = POMReader.find(self.__doc, './pom:packaging') if packaging is None: # use default packaging type return "jar" if len(packaging) != 0: raise PomLoadingException("Unexpected child nodes under packaging") return packaging.text.strip()
def from_xml_element(cls, xmlnode): """ Create Plugin from xml.etree.ElementTree.Element as contained within pom.xml. """ parts = {'groupId': '', 'artifactId': '', 'version': ''} parts = POMReader.find_parts(xmlnode, parts) if not parts['artifactId']: raise ArtifactFormatException("Empty artifactId encountered. " "This is a bug, please report it!") # dependencies depnodes = POMReader.xpath(xmlnode, "./dependencies/dependency") deps = [] for d in [Dependency.from_xml_element(x) for x in depnodes]: deps.append(d) return cls(parts['groupId'], parts['artifactId'], parts['version'], deps)
def from_xml_element(cls, xmlnode): """ Create Extension from xml.etree.ElementTree.Element as contained within pom.xml. """ parts = {'groupId': '', 'artifactId': '', 'version': ''} parts = POMReader.find_parts(xmlnode, parts) if not parts['groupId'] or not parts['artifactId']: raise ArtifactFormatException( "Empty groupId or artifactId encountered. " "This is a bug, please report it!") return cls(parts['groupId'], parts['artifactId'], parts['version'])
def properties(self): """ Dictionary consisting of properties specified in pom.xml """ properties = {} xmlnodes = POMReader.find(self.__doc, './pom:properties') if xmlnodes is None: return properties propnodes = xmlnodes.getchildren() for node in propnodes: if node.tag.startswith('{'): tag = node.tag[node.tag.find('}') + 1:] else: tag = node.tag properties[tag] = node.text return properties
def from_xml_element(cls, xmlnode): """ Create Dependency from xml.etree.ElementTree.Element as contained within pom.xml. """ parts = {'groupId': '', 'artifactId': '', 'type': '', 'classifier': '', 'version': '', 'scope': '', 'optional': ''} parts = POMReader.find_parts(xmlnode, parts) if not parts['groupId'] or not parts['artifactId']: raise ArtifactFormatException( "Empty groupId or artifactId encountered. " "This is a bug, please report it!") # exclusions excnodes = xmlnode.findall("{*}exclusions/{*}exclusion") exclusions = set() for e in [Exclusion.from_xml_element(x) for x in excnodes]: exclusions.add(e) return cls(parts['groupId'], parts['artifactId'], extension=parts['type'], classifier=parts['classifier'], version=parts['version'], scope=parts['scope'], optional=parts['optional'], exclusions=exclusions)
def __init__(self, path): self.__doc = POMReader.load(path) self._path = os.path.join(path)