3 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
4 ##############################################################################
5 # Copyright (c) 2014, 2015 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 ##############################################################################
16 from collections import OrderedDict
25 args = jjblib.parse_jjb_args()
28 project = jjblib.Project(args.project)
29 if project.meta_project is not None:
30 project_dir = os.path.join("jjb", project.meta_project, project.project)
32 project_dir = os.path.join("jjb", project.project)
34 project_file = os.path.join(project_dir, "%s.yaml" % project)
36 disabled = "true" # Always disabled unless project has dependencies
37 email_prefix = "[%s]" % project
40 jjblib.create_template_config(project_dir, args)
41 project_conf = os.path.join(project_dir, "%s.cfg" % args.project)
43 project_conf = args.conf
45 cfg = dict() # Needed to skip missing project.cfg files
46 if os.path.isfile(project_conf):
47 stream = open(project_conf, "r")
48 cfg = yaml.load(stream)
53 if cfg.get('JOB_TEMPLATES'):
54 templates = cfg.get('JOB_TEMPLATES')
56 templates = "verify,merge,daily,distribution,integration,sonar"
57 templates += ",clm" # ensure we always create a clm job for all projects
62 branches = OrderedDict()
63 if cfg.get('BRANCHES'):
64 for branch in cfg.get('BRANCHES'):
66 branches.update({b: branch[b]})
68 branches.update({"master": {"jdks": "openjdk7"}})
70 sonar_branch = list(branches.items())[0][0]
71 # Create YAML to list branches to create jobs for
73 for branch, options in branches.items():
74 streams = streams + (" - %s:\n"
76 (branch.replace('/', '-'),
78 streams = streams + " jdk: %s\n" % options["jdks"].split(",")[0].strip() # noqa
79 streams = streams + " jdks:\n"
80 for jdk in options["jdks"].split(","):
81 streams = streams + " - %s\n" % jdk.strip()
87 jdks = cfg.get('JDKS')
91 for jdk in jdks.split(","):
92 use_jdks += " - %s\n" % jdk
105 if cfg.get('MVN_GOALS'):
106 mvn_goals = cfg.get('MVN_GOALS')
108 mvn_goals = ("clean install "
109 "-V " # Show Maven / Java version before building
110 "-Dmaven.repo.local=/tmp/r "
111 "-Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r ")
116 if cfg.get('MVN_OPTS'):
117 mvn_opts = cfg.get('MVN_OPTS')
119 mvn_opts = "-Xmx1024m -XX:MaxPermSize=256m"
121 #######################
122 # Handle DEPENDENCIES #
123 #######################
124 if cfg.get('DEPENDENCIES'):
125 dependencies = cfg.get('DEPENDENCIES')
126 if dependencies.find("odlparent") < 0: # Add odlparent if not listed
127 dependencies = "odlparent," + dependencies
130 dependencies = "odlparent" # All projects depend on odlparent
133 email_prefix = (email_prefix + " " +
134 " ".join(['[%s]' % d for d in dependencies.split(",")])) # noqa
135 dependent_jobs = ",".join(
136 ['%s-merge-{stream}' % d for d in dependencies.split(",")])
138 ############################
139 # Handle ARCHIVE_ARTIFACTS #
140 ############################
141 if cfg.get('ARCHIVE_ARTIFACTS'):
142 archive_artifacts = cfg.get('ARCHIVE_ARTIFACTS')
143 archive_artifacts = ("- archive-artifacts:\n"
144 " artifacts: '%s'" % archive_artifacts)
146 archive_artifacts = ""
149 ##############################
150 # Create configuration start #
151 ##############################
153 # Create project directory if it doesn't exist
154 if not os.path.exists(project_dir):
155 os.makedirs(project_dir)
157 print("project: %s\n"
170 # Create initial project YAML file
171 use_templates = templates.split(",")
172 use_templates.insert(0, "project")
173 job_templates_yaml = ""
174 for t in use_templates:
175 if t == "project": # This is not a job type but is used for templating
178 job_templates_yaml = job_templates_yaml + \
179 " - '%s-%s'\n" % (project, t)
181 job_templates_yaml = job_templates_yaml + \
182 " - '%s-%s-{stream}'\n" % (project, t)
184 with open(project_file, "w") as outfile:
185 for t in use_templates:
186 template_file = "jjb-templates/%s.yaml" % t
187 with open(template_file, "r") as infile:
189 if not re.match("\s*#", line):
190 line = re.sub("JOB_TEMPLATES", job_templates_yaml, line)
191 line = re.sub("PROJECT", project.project, line)
192 line = re.sub("DISABLED", disabled, line)
193 line = re.sub("STREAMS", streams, line)
194 line = re.sub("POM", pom, line)
195 line = re.sub("MAVEN_GOALS", mvn_goals, line)
196 line = re.sub("MAVEN_OPTS", mvn_opts, line)
197 line = re.sub("DEPENDENCIES", dependent_jobs, line)
198 line = re.sub("EMAIL_PREFIX", email_prefix, line)
199 line = re.sub("SONAR_BRANCH", sonar_branch, line)
200 line = re.sub("ARCHIVE_ARTIFACTS", archive_artifacts, line)
201 # The previous command may have created superfluous lines.
202 # If a line has no non-whitespace, it has to be '\n' only.
203 line = re.sub(r'^\s+\n', "", line)