Created
February 23, 2012 22:10
-
-
Save kennedyj/1895332 to your computer and use it in GitHub Desktop.
quick maven pom parser for group, artifact, and version
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
#!/usr/bin/python | |
from xml.etree import ElementTree as et | |
import sys | |
if __name__ == "__main__": | |
ns = "http://maven.apache.org/POM/4.0.0" | |
for filename in sys.argv[1:len(sys.argv)]: | |
group = artifact = version = "" | |
tree = et.ElementTree() | |
tree.parse(filename) | |
p = tree.getroot().find("{%s}parent" % ns) | |
if p is not None: | |
if p.find("{%s}groupId" % ns) is not None: | |
group = p.find("{%s}groupId" % ns).text | |
if p.find("{%s}version" % ns) is not None: | |
version = p.find("{%s}version" % ns).text | |
if tree.getroot().find("{%s}groupId" % ns) is not None: | |
group = tree.getroot().find("{%s}groupId" % ns).text | |
if tree.getroot().find("{%s}artifactId" % ns) is not None: | |
artifact = tree.getroot().find("{%s}artifactId" % ns).text | |
if tree.getroot().find("{%s}version" % ns) is not None: | |
version = tree.getroot().find("{%s}version" % ns).text | |
print "mvn:%s/%s/%s" % (group, artifact, version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Going from the very top to the bottom you'll omit tag data if e. g. is also defined in the document root.