Last active
August 29, 2015 14:00
-
-
Save ihodes/11505022 to your computer and use it in GitHub Desktop.
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
# example .ensime generation | |
# Maven to Ensime config. convertor: | |
# | |
# Prints .ensime configuration for Maven project. | |
# | |
# USAGE: | |
# mvn-ensime PROJECT_NAME PROJECT_PACKAGE ROOT_DIR TARGET_DIR SOURCE_DIRS* | |
# | |
python mvn-ensime.py adam org.bdgenomics.adam \ | |
/Users/isaachodes/workspace/adam/ /Users/isaachodes/workspace/adam/target/ \ | |
/Users/isaachodes/workspace/adam/adam-core/src/ /Users/isaachodes/workspace/adam/adam-cli/src/ \ | |
/Users/isaachodes/workspace/adam/adam-format/ > .ensime |
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 subprocess | |
import sys | |
def maven_dependencies(): | |
output = subprocess.check_output(["mvn", "dependency:build-classpath"]) | |
output = output.split('\n') | |
deps = set() | |
prev_line = "" | |
for line in output: | |
line = line.strip() | |
if prev_line.startswith("[INFO] Dependencies classpath:"): | |
deps = deps.union(set(line.split(":"))) | |
prev_line = line | |
return deps | |
def quote(obj): | |
return "\"" + str(obj) + "\"" | |
def string_list(lst): | |
return " ".join(quote(ea) for ea in lst) | |
def main(args): | |
if len(args) < 4 or args[0] in ['-h', '--help']: | |
print "Maven to Ensime config. convertor:\n" | |
print "Prints .ensime configuration for Maven project.\n" | |
print "USAGE:" | |
print "mvn-ensime PROJECT_NAME PROJECT_PACKAGE ROOT_DIR TARGET_DIR SOURCE_DIRS*\n" | |
return | |
deps = maven_dependencies() | |
deps = string_list(deps) | |
print """\ | |
( | |
:project-name %s | |
:project-package %s | |
:root-dir %s | |
:target %s | |
:source-roots (%s) | |
:use-maven t | |
:compile-deps (%s) | |
:runtime-deps (%s) | |
:test-deps (%s) | |
) | |
""" % (quote(args[0]), | |
quote(args[1]), | |
quote(args[2]), | |
quote(args[3]), | |
string_list(args[4::]), | |
deps, deps, deps) | |
if __name__ == '__main__': | |
main(sys.argv[1::]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment