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 streams = OrderedDict()
63 if cfg.get("STREAMS"): # this is a list of single-key dicts
64 for stream_dict in cfg.get("STREAMS"):
65 streams.update(stream_dict)
67 streams = {"beryllium": jjblib.STREAM_DEFAULTS["beryllium"]}
69 first_stream = streams.iterkeys().next() # Keep master branch at top.
70 sonar_branch = streams[first_stream]["branch"]
71 # Create YAML to list branches to create jobs for
72 str_streams = "stream:\n"
73 for stream, options in streams.items():
74 str_streams += (" - %s:\n"
76 (stream, options["branch"]))
77 str_streams += " jdk: %s\n" % options["jdks"].split(',')[0].strip() # noqa
78 str_streams += " jdks:\n"
79 for jdk in options["jdks"].split(","):
80 str_streams += " - %s\n" % jdk.strip()
86 jdks = cfg.get('JDKS')
90 for jdk in jdks.split(","):
91 use_jdks += " - %s\n" % jdk
104 if cfg.get('MVN_GOALS'):
105 mvn_goals = cfg.get('MVN_GOALS')
107 mvn_goals = ("clean install "
108 "-V " # Show Maven / Java version before building
109 "-Dmaven.repo.local=/tmp/r "
110 "-Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r ")
115 if cfg.get('MVN_OPTS'):
116 mvn_opts = cfg.get('MVN_OPTS')
118 mvn_opts = "-Xmx1024m -XX:MaxPermSize=256m"
120 #######################
121 # Handle DEPENDENCIES #
122 #######################
123 if cfg.get('DEPENDENCIES'):
124 dependencies = cfg.get('DEPENDENCIES')
125 if dependencies.find("odlparent") < 0: # Add odlparent if not listed
126 dependencies = "odlparent," + dependencies
129 dependencies = "odlparent" # All projects depend on odlparent
132 email_prefix = (email_prefix + " " +
133 " ".join(['[%s]' % d for d in dependencies.split(",")])) # noqa
134 dependent_jobs = ",".join(
135 ['%s-merge-{stream}' % d for d in dependencies.split(",")])
137 ############################
138 # Handle ARCHIVE_ARTIFACTS #
139 ############################
140 if cfg.get('ARCHIVE_ARTIFACTS'):
141 archive_artifacts = cfg.get('ARCHIVE_ARTIFACTS')
142 archive_artifacts = ("- archive-artifacts:\n"
143 " artifacts: '%s'" % archive_artifacts)
145 archive_artifacts = ""
148 ##############################
149 # Create configuration start #
150 ##############################
152 # Create project directory if it doesn't exist
153 if not os.path.exists(project_dir):
154 os.makedirs(project_dir)
156 print("project: %s\n"
169 # Create initial project YAML file
170 use_templates = templates.split(",")
171 use_templates.insert(0, "project")
172 job_templates_yaml = ""
173 for t in use_templates:
174 if t == "project": # This is not a job type but is used for templating
177 job_templates_yaml = job_templates_yaml + \
178 " - '%s-%s'\n" % (project, t)
180 job_templates_yaml = job_templates_yaml + \
181 " - '%s-%s-{stream}'\n" % (project, t)
183 with open(project_file, "w") as outfile:
184 for t in use_templates:
185 template_file = "jjb-templates/%s.yaml" % t
186 with open(template_file, "r") as infile:
188 if not re.match("\s*#", line):
189 line = re.sub("JOB_TEMPLATES", job_templates_yaml, line)
190 line = re.sub("PROJECT", project.project, line)
191 line = re.sub("DISABLED", disabled, line)
192 line = re.sub("STREAMS", str_streams, line)
193 line = re.sub("POM", pom, line)
194 line = re.sub("MAVEN_GOALS", mvn_goals, line)
195 line = re.sub("MAVEN_OPTS", mvn_opts, line)
196 line = re.sub("DEPENDENCIES", dependent_jobs, line)
197 line = re.sub("EMAIL_PREFIX", email_prefix, line)
198 line = re.sub("SONAR_BRANCH", sonar_branch, line)
199 line = re.sub("ARCHIVE_ARTIFACTS", archive_artifacts, line)
200 # The previous command may have created superfluous lines.
201 # If a line has no non-whitespace, it has to be '\n' only.
202 line = re.sub(r'^\s+\n', "", line)