Jonathan Hart | 0b6ef8f | 2013-11-18 12:00:20 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | from os import path |
| 5 | from xml.dom import minidom |
| 6 | |
| 7 | # Location of the .classpath file relative to this script |
| 8 | classpath_filename = "../.classpath" |
| 9 | m2_repository = "~/.m2/repository" |
| 10 | |
| 11 | def parse_classpath_xml(classpath_file, abs_m2_repository): |
| 12 | xmldoc = minidom.parse(classpath_file) |
| 13 | classpathentries = xmldoc.getElementsByTagName('classpathentry') |
| 14 | classpath = "" |
| 15 | for entry in classpathentries: |
| 16 | kind = entry.attributes['kind'].value |
| 17 | if kind == "output" or kind == "var": |
| 18 | cp_entry = entry.attributes['path'].value + ":" |
| 19 | |
| 20 | classpath += cp_entry.replace("M2_REPO", abs_m2_repository) |
| 21 | |
| 22 | print classpath[0:-1] |
| 23 | |
| 24 | if __name__ == "__main__": |
| 25 | abs_m2_repository = path.expanduser("~/.m2/repository") |
| 26 | |
| 27 | classpath_file = path.abspath(path.join(path.dirname(path.realpath(sys.argv[0])), classpath_filename)) |
| 28 | |
| 29 | try: |
| 30 | with open(classpath_file) as f: |
| 31 | parse_classpath_xml(f, abs_m2_repository) |
| 32 | except IOError: |
| 33 | print "Error reading classpath file from %s" % classpath_file |
| 34 | print "- Please check path is correct then run 'mvn eclipse:eclipse' to generate file" |