File size: 893 Bytes
a87d9a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from subprocess import Popen, PIPE, STDOUT
from log_writer import logger


def build_plugin(artifact_name):
    project_path = f"codes/{artifact_name}"
    build_command = [
        "cd",
        project_path,
        "&&",
        "mvn",
        "-V",
        "-B",
        "clean",
        "package",
        "--file",
        "pom.xml",
    ]

    process = Popen(build_command, stdout=PIPE, stderr=STDOUT, shell=True)

    def log_subprocess_output(pipe):
        output = ""
        for line in iter(pipe.readline, b""):
            str_line = str(line)
            output += str_line
            logger(f"building -> {str_line}")
        return output

    with process.stdout:
        output = log_subprocess_output(process.stdout)

    process.wait()

    return output


if __name__ == "__main__":
    result = build_plugin("ExamplePlugin2")
    print(result)
    print(type(result))