Add missing -{stream} component to integration dependencies on merge jobs
[releng/builder.git] / scripts / jjb-init-project.py
1 #!/usr/bin/python
2
3 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
4 ##############################################################################
5 # Copyright (c) 2014 The Linux Foundation and others.
6 #
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Eclipse Public License v1.0
9 # which accompanies this distribution, and is available at
10 # http://www.eclipse.org/legal/epl-v10.html
11 #
12 # Contributors:
13 #   Thanh Ha (The Linux Foundation) - Initial implementation
14 ##############################################################################
15
16 import argparse
17 import os
18 import re
19
20 parser = argparse.ArgumentParser()
21 parser.add_argument("project", help="project")
22 parser.add_argument("-d", "--dependencies",
23                     help=("Project dependencies\n\n"
24                           "A comma-seperated (no spaces) list of projects "
25                           "your project depends on. "
26                           "This is used to create an integration job that "
27                           "will trigger when a dependent project-merge job "
28                           "is built successfully.\n\n"
29                           "Example: aaa,controller,yangtools"))
30 parser.add_argument("-g", "--mvn-goals", help="Maven Goals")
31 parser.add_argument("-o", "--mvn-opts", help="Maven Options")
32 args = parser.parse_args()
33
34 project = args.project
35 project_dir = os.path.join("jjb", project)
36 project_file = os.path.join(project_dir, "%s.yaml" % project)
37 mvn_goals = args.mvn_goals  # Defaults to "clean install" if not passsed
38 mvn_opts = args.mvn_opts    # Defaults to blank if not passed
39 dependencies = args.dependencies
40 dependent_jobs = ""
41 disabled = "true"   # Always disabled unless project has dependencies
42 email_prefix = "[%s]" % project
43
44 template_file = os.path.join("jjb", "job.yaml.template")
45
46 if not mvn_goals:
47     mvn_goals = ("clean install "
48                  "-V "  # Show Maven / Java version before building
49                  "-Dmaven.repo.local=$WORKSPACE/.m2repo "
50                  "-Dorg.ops4j.pax.url.mvn.localRepository=$WORKSPACE/.m2repo ")
51
52 if not mvn_opts:
53     mvn_opts = "-Xmx1024m -XX:MaxPermSize=256m"
54
55 if dependencies:
56     disabled = "false"
57     email_prefix = (email_prefix + " " +
58                     " ".join(['[%s]' % d for d in dependencies.split(",")]))
59     dependent_jobs = ",".join(
60         ['%s-merge-{stream}' % d for d in dependencies.split(",")])
61
62 # Create project directory if it doesn't exist
63 if not os.path.exists(project_dir):
64     os.makedirs(project_dir)
65
66 print("project: %s\n"
67       "goals: %s\n"
68       "options: %s\n"
69       "dependencies: %s" %
70       (project,
71        mvn_goals,
72        mvn_opts,
73        dependencies))
74
75 # Create initial project YAML file
76 with open(template_file, "r") as infile:
77     with open(project_file, "w") as outfile:
78         for line in infile:
79             if not re.match("\s*#", line):
80                 line = re.sub("PROJECT", project, line)
81                 line = re.sub("DISABLED", disabled, line)
82                 line = re.sub("MAVEN_GOALS", mvn_goals, line)
83                 line = re.sub("MAVEN_OPTS", mvn_opts, line)
84                 line = re.sub("DEPENDENCIES", dependent_jobs, line)
85                 line = re.sub("EMAIL_PREFIX", email_prefix, line)
86             outfile.write(line)