Last active
August 12, 2020 00:22
-
-
Save jkeam/d6fe3611fe882a3cbfc71c06e5eca396 to your computer and use it in GitHub Desktop.
Pom Reports Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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