Skip to content

Instantly share code, notes, and snippets.

@jkeam
Last active August 12, 2020 00:22
Show Gist options
  • Save jkeam/d6fe3611fe882a3cbfc71c06e5eca396 to your computer and use it in GitHub Desktop.
Save jkeam/d6fe3611fe882a3cbfc71c06e5eca396 to your computer and use it in GitHub Desktop.
Pom Reports Directory
import xml.etree.ElementTree as ET
import re
def find_reports_dir(pom_file):
""" Return the report directory specified in the pom """
# extract and set namespace
root = ET.parse(pom_file).getroot()
m = re.findall(r'{(.*?)}', root.tag)
namespace = m[0] if m else ''
ns = {'maven': namespace}
# extract reportsDirectory
xpath = 'maven:build/'\
'maven:plugins/'\
'maven:plugin/'\
'[maven:artifactId="maven-surefire-plugin"]/'\
'maven:configuration/'\
'maven:reportsDirectory'
plugin = root.find(xpath, ns)
return None if plugin is None else plugin.text
# main
reports_dir = find_reports_dir('pom.xml')
print(reports_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment