Created
June 12, 2015 20:53
-
-
Save Gastove/08fac197ffc71117ebf0 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
#!/usr/local/bin/python | |
# | |
# Lifted from: https://gist.github.com/ihodes/11505022 | |
# 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 | |
# | |
# NOTE: This does not actually work. It gets you _most_ of the way there, | |
# but not all. You're gonna want to look over this: | |
# https://github.com/ensime/ensime-server/wiki/Example-Configuration-File | |
# to get your configs right, at least until Ross figures out how to unfuck this | |
# script. | |
import subprocess | |
import sys | |
import os | |
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 line and 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) + "\n" for ea in lst) | |
def mk_src_roots(base): | |
main = os.path.join(base, *["src", "main", "scala"]) | |
test = os.path.join(base, *["src", "test", "scala"]) | |
return string_list([main, test]) | |
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 MODULE_NAME PROJECT_PACKAGE ROOT_DIR TARGET_DIR*\n" | |
return | |
deps = maven_dependencies() | |
deps = string_list(deps) | |
name, sub_name, package, root = args | |
scala = "2.10.5" | |
cache = os.path.join(root, ".ensime_cache/") | |
base = os.path.join(root, sub_name) | |
target = os.path.join(base, "target/scala-2.10/classes") | |
test_target = target # These may eventually be different | |
src_roots = mk_src_roots(base) | |
java_home = os.getenv("JAVA_HOME") | |
tpl = """ | |
( | |
:name "{name}" | |
:package "{package}" | |
:root-dir "{root}" | |
:cache-dir "{cache}" | |
:scala-version "{scala}" | |
:java-home "{java_home}" | |
:subprojects (( | |
:name "{sub_name}" | |
:depends-on-modules nil | |
:target "{target}" | |
:test-target "{test_target}" | |
:source-roots ({src_roots}) | |
:compile-deps ({deps}) | |
:runtime-deps ({deps}) | |
:test-deps ({deps}) | |
)) | |
) | |
""" | |
fmt_args = { | |
"name": name, | |
"package": package, | |
"root": root, | |
"scala": scala, | |
"sub_name": sub_name, | |
"cache": cache, | |
"target": target, | |
"test_target": test_target, | |
"src_roots": src_roots, | |
"deps": deps, | |
"java_home": java_home | |
} | |
res = tpl.format(**fmt_args) | |
print res | |
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