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)
31 jenkins_settings = "%s-%s-settings" % (project.meta_project,
34 project_dir = os.path.join("jjb", project.project)
35 jenkins_settings = "%s-settings" % project.project
37 project_file = os.path.join(project_dir, "%s.yaml" % project)
39 disabled = "true" # Always disabled unless project has dependencies
40 email_prefix = "[%s]" % project
44 jjblib.create_template_config(project_dir, args)
45 project_conf = os.path.join(project_dir, "%s.cfg" % args.project)
47 project_conf = args.conf
49 cfg = dict() # Needed to skip missing project.cfg files
50 if os.path.isfile(project_conf):
51 stream = open(project_conf, "r")
52 cfg = yaml.load(stream)
57 if cfg.get("JOB_TEMPLATES"):
58 templates = cfg.get("JOB_TEMPLATES")
61 "verify,merge,periodic,distribution,distribution-check,integration,"
63 templates += ",clm" # ensure we always create a clm job for all projects
64 templates += ",validate-autorelease" # Autorelease validate template
69 streams = OrderedDict()
70 if cfg.get("STREAMS"): # this is a list of single-key dicts
71 for stream_dict in cfg.get("STREAMS"):
72 streams.update(stream_dict)
74 streams = {"boron": jjblib.STREAM_DEFAULTS["boron"]}
76 first_stream = streams.iterkeys().next() # Keep master branch at top.
77 sonar_branch = streams[first_stream]["branch"]
78 # Create YAML to list branches to create jobs for
79 str_streams = "stream:\n"
80 for stream, options in streams.items():
81 str_streams += (" - %s:\n"
83 (stream, options["branch"]))
84 str_streams += " jdk: %s\n" % options["jdks"].split(',')[0].strip() # noqa
85 str_streams += " jdks:\n"
86 for jdk in options["jdks"].split(","):
87 str_streams += " - %s\n" % jdk.strip()
89 # Disable autorelease validate job unless project is participating
90 # in autorelease, JJB does not allow flipping a boolean so we have to
91 # flip it here via not operator since the JJB configuration for disabling
92 # a Jenkins Job is "disabled: bool".
93 str_streams += " disable_autorelease: %s\n" % (not options.get(
94 "autorelease", False))
96 # Disable the distribution-check job unless project enables it
97 str_streams += " disable_distribution_check: %s\n" % (
98 not options.get("distribution-check", True))
104 jdks = cfg.get('JDKS')
108 for jdk in jdks.split(","):
109 use_jdks += " - %s\n" % jdk
122 if cfg.get('MVN_GOALS'):
123 mvn_goals = cfg.get('MVN_GOALS')
125 mvn_goals = ("clean install "
126 "-V " # Show Maven / Java version before building
127 "-Dmaven.repo.local=/tmp/r "
128 "-Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r ")
133 if cfg.get('MVN_OPTS'):
134 mvn_opts = cfg.get('MVN_OPTS')
136 mvn_opts = "-Xmx1024m -XX:MaxPermSize=256m"
138 #######################
139 # Handle DEPENDENCIES #
140 #######################
141 if cfg.get('DEPENDENCIES'):
142 dependencies = cfg.get('DEPENDENCIES')
143 if dependencies.find("odlparent") < 0: # Add odlparent if not listed
144 dependencies = "odlparent," + dependencies
148 if project.project != "odlparent": # Odlparent does not depend on itself
149 dependencies = "odlparent" # All other projects depend on odlparent
153 email_prefix = (email_prefix + " " +
154 " ".join(['[%s]' % d for d in dependencies.split(",")])) # noqa
155 dependent_jobs = ",".join(
156 ['%s-merge-{stream}' % d for d in dependencies.split(",")])
158 ############################
159 # Handle ARCHIVE_ARTIFACTS #
160 ############################
162 always_archive = "**/target/surefire-reports/*-output.txt"
164 archive_artifacts = cfg.get('ARCHIVE_ARTIFACTS', '')
165 archive_artifacts = ("- archive-artifacts:\n"
166 " artifacts: '%s, %s'" %
167 (always_archive, archive_artifacts))
169 ##############################
170 # Create configuration start #
171 ##############################
173 # Create project directory if it doesn't exist
174 if not os.path.exists(project_dir):
175 os.makedirs(project_dir)
177 print("project: %s\n"
190 # Create initial project YAML file
191 use_templates = templates.split(",")
192 use_templates.insert(0, "project")
193 job_templates_yaml = ""
194 for t in use_templates:
195 if t == "project": # This is not a job type but is used for templating
198 job_templates_yaml = job_templates_yaml + \
199 " - '%s-%s'\n" % (project, t)
201 job_templates_yaml = job_templates_yaml + \
202 " - '%s-%s-{stream}'\n" % (project, t)
204 with open(project_file, "w") as outfile:
205 for t in use_templates:
206 template_file = "jjb-templates/%s.yaml" % t
207 with open(template_file, "r") as infile:
209 if not re.match("\s*#", line):
210 line = re.sub("JOB_TEMPLATES", job_templates_yaml, line)
211 line = re.sub("PROJECT_SHORTNAME", project.project, line)
212 line = re.sub("PROJECT_PATH", project.path, line)
213 line = re.sub("JENKINS_SETTINGS", jenkins_settings, line)
214 line = re.sub("DISABLED", disabled, line)
215 line = re.sub("STREAMS", str_streams, line)
216 line = re.sub("POM", pom, line)
217 line = re.sub("MAVEN_GOALS", mvn_goals, line)
218 line = re.sub("MAVEN_OPTS", mvn_opts, line)
219 line = re.sub("DEPENDENCIES", dependent_jobs, line)
220 line = re.sub("EMAIL_PREFIX", email_prefix, line)
221 line = re.sub("SONAR_BRANCH", sonar_branch, line)
222 line = re.sub("ARCHIVE_ARTIFACTS", archive_artifacts, line)
223 # The previous command may have created superfluous lines.
224 # If a line has no non-whitespace, it has to be '\n' only.
225 line = re.sub(r'^\s+\n', "", line)