Show Maven / Java version before starting build
[releng/builder.git] / scripts / jjb-init-project.py
1 #!/usr/bin/python
2
3 # @License EPL-1.0 <http://spdx.org/licenses/EPL-1.0>
4 ##############################################################################
5 # Copyright (c) 2014 The Linux Foundation and others.
6 #
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
11 #
12 # Contributors:
13 #   Thanh Ha (The Linux Foundation) - Initial implementation
14 ##############################################################################
15
16 import argparse
17 import os
18 import re
19
20 parser = argparse.ArgumentParser()
21 parser.add_argument("project", help="project")
22 parser.add_argument("-g", "--mvn-goals", help="Maven Goals")
23 parser.add_argument("-o", "--mvn-opts", help="Maven Options")
24 args = parser.parse_args()
25
26 project = args.project
27 project_dir = os.path.join("jjb", project)
28 project_file = os.path.join(project_dir, "%s.yaml" % project)
29 mvn_goals = args.mvn_goals  # Defaults to "clean install" if not passsed
30 mvn_opts = args.mvn_opts    # Defaults to blank if not passed
31
32 template_file = os.path.join("jjb", "job.yaml.template")
33
34 if not mvn_goals:
35     mvn_goals = ("clean install "
36                  "-V "  # Show Maven / Java version before building
37                  "-Dmaven.repo.local=$WORKSPACE/.m2repo "
38                  "-Dorg.ops4j.pax.url.mvn.localRepository=$WORKSPACE/.m2repo ")
39
40 if not mvn_opts:
41     mvn_opts = "-Xmx1024m -XX:MaxPermSize=256m"
42
43 # Create project directory if it doesn't exist
44 if not os.path.exists(project_dir):
45     os.makedirs(project_dir)
46
47 print("project: %s\ngoals: %s\noptions: %s" % (project,
48                                                mvn_goals,
49                                                mvn_opts))
50
51 # Create initial project YAML file
52 with open(template_file, "r") as infile:
53     with open(project_file, "w") as outfile:
54         for line in infile:
55             if not re.match("\s*#", line):
56                 line = re.sub("PROJECT", project, line)
57             if not re.match("\s*#", line):
58                 line = re.sub("MAVEN_GOALS", mvn_goals, line)
59             if not re.match("\s*#", line):
60                 line = re.sub("MAVEN_OPTS", mvn_opts, line)
61             outfile.write(line)