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 ##############################################################################
16 from collections import OrderedDict
25 args = jjblib.parse_jjb_args()
27 project = args.project
28 project_dir = os.path.join("jjb", project)
29 project_file = os.path.join(project_dir, "%s.yaml" % project)
31 disabled = "true" # Always disabled unless project has dependencies
32 email_prefix = "[%s]" % project
35 jjblib.create_template_config(project_dir, args)
36 project_conf = os.path.join(project_dir, "%s.cfg" % args.project)
38 project_conf = args.conf
40 cfg = dict() # Needed to skip missing project.cfg files
41 if os.path.isfile(project_conf):
42 stream = open(project_conf, "r")
43 cfg = yaml.load(stream)
48 if cfg.get('JOB_TEMPLATES'):
49 templates = cfg.get('JOB_TEMPLATES')
51 templates = "verify,merge,daily,distribution,integration,sonar"
52 templates += ",clm" # ensure we always create a clm job for all projects
57 branches = OrderedDict()
58 if cfg.get('BRANCHES'):
59 for branch in cfg.get('BRANCHES'):
61 branches.update({b: branch[b]})
63 branches.update({"master": {"jdks": "openjdk7"}})
64 branches.update({"stable/helium": {"jdks": "openjdk7"}})
66 sonar_branch = list(branches.items())[0][0]
67 # Create YAML to list branches to create jobs for
69 for branch, options in branches.items():
70 streams = streams + (" - %s:\n"
72 (branch.replace('/', '-'),
74 streams = streams + " jdk: %s\n" % options["jdks"].split(",")[0].strip() # noqa
75 streams = streams + " jdks:\n"
76 for jdk in options["jdks"].split(","):
77 streams = streams + " - %s\n" % jdk.strip()
83 jdks = cfg.get('JDKS')
87 for jdk in jdks.split(","):
88 use_jdks += " - %s\n" % jdk
101 if cfg.get('MVN_GOALS'):
102 mvn_goals = cfg.get('MVN_GOALS')
104 mvn_goals = ("clean install "
105 "-V " # Show Maven / Java version before building
106 "-Dmaven.repo.local=/tmp/r "
107 "-Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r ")
112 if cfg.get('MVN_OPTS'):
113 mvn_opts = cfg.get('MVN_OPTS')
115 mvn_opts = "-Xmx1024m -XX:MaxPermSize=256m"
117 #######################
118 # Handle DEPENDENCIES #
119 #######################
120 if cfg.get('DEPENDENCIES'):
121 dependencies = cfg.get('DEPENDENCIES')
122 if dependencies.find("odlparent") < 0: # Add odlparent if not listed
123 dependencies = "odlparent," + dependencies
126 dependencies = "odlparent" # All projects depend on odlparent
129 email_prefix = (email_prefix + " " +
130 " ".join(['[%s]' % d for d in dependencies.split(",")])) # noqa
131 dependent_jobs = ",".join(
132 ['%s-merge-{stream}' % d for d in dependencies.split(",")])
134 ############################
135 # Handle ARCHIVE_ARTIFACTS #
136 ############################
137 if cfg.get('ARCHIVE_ARTIFACTS'):
138 archive_artifacts = cfg.get('ARCHIVE_ARTIFACTS')
139 archive_artifacts = ("- archive-artifacts:\n"
140 " artifacts: '%s'" % archive_artifacts)
142 archive_artifacts = ""
145 ##############################
146 # Create configuration start #
147 ##############################
149 # Create project directory if it doesn't exist
150 if not os.path.exists(project_dir):
151 os.makedirs(project_dir)
153 print("project: %s\n"
166 # Create initial project YAML file
167 use_templates = templates.split(",")
168 use_templates.insert(0, "project")
169 job_templates_yaml = ""
170 for t in use_templates:
171 if t == "project": # This is not a job type but is used for templating
173 elif t == "sonar" or t == "clm":
174 job_templates_yaml = job_templates_yaml + \
175 " - '%s-%s'\n" % (project, t)
177 job_templates_yaml = job_templates_yaml + \
178 " - '%s-%s-{stream}'\n" % (project, t)
180 with open(project_file, "w") as outfile:
181 for t in use_templates:
182 template_file = "jjb-templates/%s.yaml" % t
183 with open(template_file, "r") as infile:
185 if not re.match("\s*#", line):
186 line = re.sub("JOB_TEMPLATES", job_templates_yaml, line)
187 line = re.sub("PROJECT", project, line)
188 line = re.sub("DISABLED", disabled, line)
189 line = re.sub("STREAMS", streams, line)
190 line = re.sub("POM", pom, line)
191 line = re.sub("MAVEN_GOALS", mvn_goals, line)
192 line = re.sub("MAVEN_OPTS", mvn_opts, line)
193 line = re.sub("DEPENDENCIES", dependent_jobs, line)
194 line = re.sub("EMAIL_PREFIX", email_prefix, line)
195 line = re.sub("SONAR_BRANCH", sonar_branch, line)
196 line = re.sub("ARCHIVE_ARTIFACTS", archive_artifacts, line)
197 # The previous command may have created superfluous lines.
198 # If a line has no non-whitespace, it has to be '\n' only.
199 line = re.sub(r'^\s+\n', "", line)