Last Updated: February 25, 2016
·
1.774K
· papaloizouc

for those who build multiple maven projects at once

python build.py

output:

1  project1
2  project2
3  project3
choose projects coma separated(e.g. [1,2,3]):
[1,2,3]
SUCCESS for /home/foobar/git/project1
SUCCESS for /home/foobar/git/project2
SUCCESS for /home/foobar/git/project3

________________________________


root = "/home/foobar/git/"
import os
from collections import OrderedDict
import subprocess


def log(out, dir):
    if "[INFO] BUILD SUCCESS\n[INFO]" in str(out, "UTF-8"):
        print("SUCCESS for %s " % dir)
    else:
        with open("log.log", "wb") as f:
            f.write(out)
        print("FAILED for %s see %s" % (dir, dir + "/log.log"))


def run(dir):
    os.chdir(dir)
    process = subprocess.Popen(
        "mvn clean install -DskipTests=true",
        shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    out, err = process.communicate()
    log(out, dir)
    errcode = process.returncode
    return (out, err, errcode)


def get_items(dir):
    sorted_list = sorted(
        filter(
            lambda x: not os.path.isfile(os.path.join(dir, x)) and not x.startswith(".")
            ,[i for i in os.listdir(dir)]
        )
    )
    sorted_list = [os.path.join(root, i) for i in sorted_list]
    return OrderedDict(zip(range(0, len(sorted_list)), sorted_list))


if __name__ == "__main__":
    display_items = get_items(root)
    #print options
    list(map(print,
             ["%s   %s" % (k, v) for k, v in display_items.items()]
    ))
    #ask for projects to compile
    input_ = eval(input("choose projects coma separated:\n "))
    #build projects!
    list(map(run, [display_items[int(i)] for i in input_]))

1 Response
Add your response

so i build this one day i had 4 terminals open all cross-spilt multiple tabs each and looking for 5 different projects to build. now i just say [1,2,3,4,5] or whatever. Sorry if it doesnt look good in the website but the script works and you dont have to cd everywhere.

over 1 year ago ·