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 ##############################################################################
24 args = jjblib.parse_jjb_args()
26 project = args.project
27 project_dir = os.path.join("jjb", project)
28 project_file = os.path.join(project_dir, "%s.yaml" % project)
30 disabled = "true" # Always disabled unless project has dependencies
31 email_prefix = "[%s]" % project
34 jjblib.create_template_config(project_dir, args)
35 project_conf = os.path.join(project_dir, "%s.cfg" % args.project)
37 project_conf = args.conf
39 cfg = dict() # Needed to skip missing project.cfg files
40 if os.path.isfile(project_conf):
41 stream = open(project_conf, "r")
42 cfg = yaml.load(stream)
47 if cfg.get('JOB_TEMPLATES'):
48 templates = cfg.get('JOB_TEMPLATES')
50 templates = "verify,merge,daily,integration,sonar"
51 templates += ",clm" # ensure we always create a clm job for all projects
56 if cfg.get('BRANCHES'):
57 branches = cfg.get('BRANCHES')
58 sonar_branch = branches.split(",")[0]
60 branches = "master,stable/helium"
61 sonar_branch = 'master'
62 # Create YAML to list branches to create jobs for
64 for branch in branches.split(","):
65 streams = streams + (" - %s:\n"
67 (branch.replace('/', '-'),
74 jdks = cfg.get('JDKS')
78 for jdk in jdks.split(","):
79 use_jdks += " - %s\n" % jdk
92 if cfg.get('MVN_GOALS'):
93 mvn_goals = cfg.get('MVN_GOALS')
95 mvn_goals = ("clean install "
96 "-V " # Show Maven / Java version before building
97 "-Dmaven.repo.local=/tmp/r "
98 "-Dorg.ops4j.pax.url.mvn.localRepository=/tmp/r ")
103 if cfg.get('MVN_OPTS'):
104 mvn_opts = cfg.get('MVN_OPTS')
106 mvn_opts = "-Xmx1024m -XX:MaxPermSize=256m"
108 #######################
109 # Handle DEPENDENCIES #
110 #######################
111 if cfg.get('DEPENDENCIES'):
112 dependencies = cfg.get('DEPENDENCIES')
113 if dependencies.find("odlparent") < 0: # Add odlparent if not listed
114 dependencies = "odlparent," + dependencies
117 dependencies = "odlparent" # All projects depend on odlparent
120 email_prefix = (email_prefix + " " +
121 " ".join(['[%s]' % d for d in dependencies.split(",")])) # noqa
122 dependent_jobs = ",".join(
123 ['%s-merge-{stream}' % d for d in dependencies.split(",")])
125 ############################
126 # Handle ARCHIVE_ARTIFACTS #
127 ############################
128 if cfg.get('ARCHIVE_ARTIFACTS'):
129 archive_artifacts = cfg.get('ARCHIVE_ARTIFACTS')
130 archive_artifacts = ("- archive-artifacts:\n"
131 " artifacts: '%s'" % archive_artifacts)
133 archive_artifacts = ""
136 ##############################
137 # Create configuration start #
138 ##############################
140 # Create project directory if it doesn't exist
141 if not os.path.exists(project_dir):
142 os.makedirs(project_dir)
144 print("project: %s\n"
157 # Create initial project YAML file
158 use_templates = templates.split(",")
159 use_templates.insert(0, "project")
160 job_templates_yaml = ""
161 for t in use_templates:
162 if t == "project": # This is not a job type but is used for templating
164 elif t == "sonar" or t == "clm":
165 job_templates_yaml = job_templates_yaml + \
166 " - '%s-%s'\n" % (project, t)
168 job_templates_yaml = job_templates_yaml + \
169 " - '%s-%s-{stream}'\n" % (project, t)
171 with open(project_file, "w") as outfile:
172 for t in use_templates:
173 template_file = "jjb-templates/%s.yaml" % t
174 with open(template_file, "r") as infile:
176 if not re.match("\s*#", line):
177 line = re.sub("JOB_TEMPLATES", job_templates_yaml, line)
178 line = re.sub("PROJECT", project, line)
179 line = re.sub("DISABLED", disabled, line)
180 line = re.sub("STREAMS", streams, line)
181 line = re.sub("JDKS", use_jdks, line)
182 line = re.sub("POM", pom, line)
183 line = re.sub("MAVEN_GOALS", mvn_goals, line)
184 line = re.sub("MAVEN_OPTS", mvn_opts, line)
185 line = re.sub("DEPENDENCIES", dependent_jobs, line)
186 line = re.sub("EMAIL_PREFIX", email_prefix, line)
187 line = re.sub("SONAR_BRANCH", sonar_branch, line)
188 line = re.sub("ARCHIVE_ARTIFACTS", archive_artifacts, line)