3 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
4 ##############################################################################
5 # Copyright (c) 2014 The Linux Foundation and others.
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
13 # Thanh Ha (The Linux Foundation) - Initial implementation
14 ##############################################################################
22 args = jjblib.parse_jjb_args()
24 project = args.project
25 project_dir = os.path.join("jjb", project)
26 project_file = os.path.join(project_dir, "%s.yaml" % project)
27 templates = args.templates # Defaults to all templates
28 branches = args.branches # Defaults to "master,stable/helium" if not passed
29 jdks = args.jdks # Defaults to openjdk7
30 pom = args.pom # Defaults to pom.xml
31 mvn_goals = args.mvn_goals # Defaults to "clean install" if not passsed
32 mvn_opts = args.mvn_opts # Defaults to blank if not passed
33 dependencies = args.dependencies
35 disabled = "true" # Always disabled unless project has dependencies
36 email_prefix = "[%s]" % project
37 archive_artifacts = args.archive_artifacts
39 # The below 2 variables are used to determine if we should generate a CFG file
40 # for a project automatically.
42 # no_cfg - is a commandline parameter that can be used by scripts such as the
43 # jjb-autoupdate-project script to explicitly disable generating CFG
45 # make_cfg - is a internal variable used to decide if we should try to
46 # auto generate the CFG file for a project based on optional
47 # variables passed by the user on the commandline.
49 make_cfg = False # Set to true if we need to generate initial CFG file
53 templates = "verify,merge,daily,integration,sonar"
56 cfg_string.append("JOB_TEMPLATES: %s" % templates)
57 templates += ",clm" # ensure we always create a clm job for all projects
60 branches = "master,stable/helium"
61 sonar_branch = "master"
64 cfg_string.append("BRANCHES: %s" % branches)
65 # For projects who use a different development branch than master
66 sonar_branch = branches.split(",")[0]
67 # Create YAML to list branches to create jobs for
69 for branch in branches.split(","):
70 streams = streams + (" - %s:\n"
72 (branch.replace('/', '-'),
79 cfg_string.append("JDKS: %s" % jdks)
81 for jdk in jdks.split(","):
82 use_jdks += " - %s\n" % jdk
88 cfg_string.append("POM: %s" % pom)
91 mvn_goals = ("clean install "
92 "-V " # Show Maven / Java version before building
93 "-Dmaven.repo.local=/tmp/r "
94 "-Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r ")
95 else: # User explicitly set MAVEN_OPTS so create CFG
97 cfg_string.append("MAVEN_GOALS: %s" % mvn_goals)
100 mvn_opts = "-Xmx1024m -XX:MaxPermSize=256m"
101 else: # User explicitly set MAVEN_OPTS so create CFG
103 cfg_string.append("MAVEN_OPTS: %s" % mvn_opts)
106 dependencies = "odlparent" # All projects depend on odlparent
108 if dependencies.find("odlparent") < 0: # If odlparent is not listed add it
109 dependencies = "odlparent," + dependencies
112 email_prefix = (email_prefix + " " +
113 " ".join(['[%s]' % d for d in dependencies.split(",")]))
114 dependent_jobs = ",".join(
115 ['%s-merge-{stream}' % d for d in dependencies.split(",")])
116 cfg_string.append("DEPENDENCIES: %s" % dependencies)
118 if not archive_artifacts:
119 archive_artifacts = ""
121 cfg_string.append("ARCHIVE: %s" % archive_artifacts)
122 archive_artifacts = ("- archive-artifacts:\n"
123 " artifacts: '%s'" % archive_artifacts)
125 ##############################
126 # Create configuration start #
127 ##############################
129 # Create project directory if it doesn't exist
130 if not os.path.exists(project_dir):
131 os.makedirs(project_dir)
133 print("project: %s\n"
146 # Create initial project CFG file
147 if not no_cfg and make_cfg:
148 print("Creating %s.cfg file" % project)
149 cfg_file = os.path.join(project_dir, "%s.cfg" % project)
150 with open(cfg_file, "w") as outstream:
151 cfg = "\n".join(cfg_string)
154 # Create initial project YAML file
155 use_templates = templates.split(",")
156 use_templates.insert(0, "project")
157 job_templates_yaml = ""
158 for t in use_templates:
159 if t == "project": # This is not a job type but is used for templating
161 elif t == "sonar" or t == "clm":
162 job_templates_yaml = job_templates_yaml + \
163 " - '%s-%s'\n" % (project, t)
165 job_templates_yaml = job_templates_yaml + \
166 " - '%s-%s-{stream}'\n" % (project, t)
168 with open(project_file, "w") as outfile:
169 for t in use_templates:
170 template_file = "jjb-templates/%s.yaml" % t
171 with open(template_file, "r") as infile:
173 if not re.match("\s*#", line):
174 line = re.sub("JOB_TEMPLATES", job_templates_yaml, line)
175 line = re.sub("PROJECT", project, line)
176 line = re.sub("DISABLED", disabled, line)
177 line = re.sub("STREAMS", streams, line)
178 line = re.sub("JDKS", use_jdks, line)
179 line = re.sub("POM", pom, line)
180 line = re.sub("MAVEN_GOALS", mvn_goals, line)
181 line = re.sub("MAVEN_OPTS", mvn_opts, line)
182 line = re.sub("DEPENDENCIES", dependent_jobs, line)
183 line = re.sub("EMAIL_PREFIX", email_prefix, line)
184 line = re.sub("SONAR_BRANCH", sonar_branch, line)
185 line = re.sub("ARCHIVE_ARTIFACTS", archive_artifacts, line)