add the --env option to maven-build, to set environment variables in the build environment

This commit is contained in:
Mike Bonnet 2011-03-30 18:27:00 -04:00
parent 3483700817
commit 29d7d550e8
3 changed files with 28 additions and 5 deletions

View file

@ -152,7 +152,8 @@ class BuildRoot(object):
self.name = "%(tag_name)s-%(id)s-%(repoid)s" % vars(self)
self.config = self.session.getBuildConfig(self.tag_id, event=self.event_id)
def _new(self, tag, arch, task_id, repo_id=None, install_group='build', setup_dns=False, bind_opts=None, maven_opts=None):
def _new(self, tag, arch, task_id, repo_id=None, install_group='build',
setup_dns=False, bind_opts=None, maven_opts=None, maven_envs=None):
"""Create a brand new repo"""
if not repo_id:
raise koji.BuildrootError, "A repo id must be provided"
@ -185,8 +186,9 @@ class BuildRoot(object):
self.name = "%(tag_name)s-%(id)s-%(repoid)s" % vars(self)
self.install_group = install_group
self.setup_dns = setup_dns
self.maven_opts = maven_opts
self.bind_opts = bind_opts
self.maven_opts = maven_opts
self.maven_envs = maven_envs
self._writeMockConfig()
def _writeMockConfig(self):
@ -206,6 +208,7 @@ class BuildRoot(object):
opts['use_host_resolv'] = self.setup_dns
opts['install_group'] = self.install_group
opts['maven_opts'] = self.maven_opts
opts['maven_envs'] = self.maven_envs
opts['bind_opts'] = self.bind_opts
output = koji.genMockConfig(self.name, self.br_arch, managed=True, **opts)
@ -1067,6 +1070,8 @@ class MavenTask(MultiPlatformTask):
build_opts['profiles'] = opts['profiles']
if opts.get('properties'):
build_opts['properties'] = opts['properties']
if opts.get('envs'):
build_opts['envs'] = opts['envs']
if opts.get('patches'):
build_opts['patches'] = opts['patches']
if opts.get('packages'):
@ -1172,7 +1177,7 @@ class BuildMavenTask(BaseTaskHandler):
maven_opts.append('-Xmx2048m')
buildroot = BuildRoot(self.session, self.options, build_tag['id'], br_arch, self.id,
install_group='maven-build', setup_dns=True, repo_id=repo_id,
maven_opts=' '.join(maven_opts))
maven_opts=maven_opts, maven_envs=opts.get('envs'))
buildroot.workdir = self.workdir
self.logger.debug("Initializing buildroot")
buildroot.init()

View file

@ -952,6 +952,9 @@ def handle_maven_build(options, session, args):
parser.add_option("-D", "--property", action="append",
dest="properties", metavar="NAME=VALUE", default=[],
help=_("Pass a system property to the Maven build"))
parser.add_option("-E", "--env", action="append",
dest="envs", metavar="NAME=VALUE", default=[],
help=_("Set an environment variable"))
parser.add_option("-p", "--package", action="append",
dest="packages", metavar="PACKAGE", default=[],
help=_("Install an additional package into the buildroot"))
@ -1009,6 +1012,15 @@ def handle_maven_build(options, session, args):
props[fields[0]] = fields[1]
if props:
opts['properties'] = props
envs = {}
for env in build_opts.envs:
fields = env.split('=', 1)
if len(fields) != 2:
parser.error(_("Environment variables must be in NAME=VALUE format"))
assert False
envs[fields[0]] = fields[1]
if envs:
opts['envs'] = envs
priority = None
if build_opts.background:
#relative to koji.PRIO_DEFAULT

View file

@ -1259,8 +1259,14 @@ def genMockConfig(name, arch, managed=False, repoid=None, tag_name=None, **opts)
etc_hosts = file('/etc/hosts')
files['etc/hosts'] = etc_hosts.read()
etc_hosts.close()
if opts.get('maven_opts', False):
files['etc/mavenrc'] = 'MAVEN_OPTS="%s"\n' % opts['maven_opts']
mavenrc = ''
if opts.get('maven_opts'):
mavenrc = 'export MAVEN_OPTS="%s"\n' % ' '.join(opts['maven_opts'])
if opts.get('maven_envs'):
for name, val in opts['maven_envs'].iteritems():
mavenrc += 'export %s="%s"\n' % (name, val)
if mavenrc:
files['etc/mavenrc'] = mavenrc
config_opts['yum.conf'] = """[main]
cachedir=/var/cache/yum