Package apama :: Module build
[hide private]
[frames] | no frames]

Source Code for Module apama.build

 1  # Copyright (c) 2015-2016 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. 
 2  # Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG 
 3  # 
 4  # $Revision: 292660 $ 
 5  # 
 6   
 7  import os 
 8  from pysys.constants import * 
 9  from apama.common import _initProject, stringToUnicode 
10   
11 -def antBuild(parent, buildfile, args=None, workingDir='build', timeout=60, environs=None):
12 """ 13 Run an ant build file with Apama environment properties set, 14 typically to generate a project artifact such as a Java plugin or adapter. 15 16 Runs in a 'build' subdirectory of the parent's output directory. 17 18 Be careful to ensure that the ant build file generates its output 19 under its working directory, or under an explicitly specified directory 20 that is located inside the test output directory. 21 22 @param parent: a ProcessUser object (such as a BaseTest) 23 @param buildfile: absolute path to the ant build.xml to run 24 @param args: an optional list of arguments to pass to ant, such as targets to build or -Dprop=value properties. 25 @param workingDir: the working directory for ant, which can be relative to the parent's output directory. Will be created if it doesn't exist. 26 @param timeout: The timeout to run ant 27 @param environs: a dictionary of environment variables (key, value) for ANT execution. 28 29 Throws an exception if the ant build does not complete successfully. 30 """ 31 displayName = 'ant' 32 buildfile = os.path.normpath(buildfile) 33 34 if not os.path.isabs(workingDir): workingDir = parent.output+'/'+workingDir 35 outdir = workingDir 36 if not os.path.exists(outdir): os.makedirs(outdir) 37 38 dstdout, dstderr = parent.allocateUniqueStdOutErr(displayName) 39 40 ant = os.path.normpath(os.getenv('ANT_HOME')+'/bin/ant'+('.bat' if PLATFORM=='win32' else '')) 41 if not os.path.exists(ant): raise Exception('Cannot find ant at: "%s"'%ant) 42 43 _initProject(parent.project) 44 45 antenvirons = {} 46 # don't copy parent process env (for safety), but some specific env vars 47 # should be copied if present 48 for varname in ['_JAVA_OPTIONS']: 49 if varname in os.environ: 50 antenvirons[varname] = stringToUnicode(os.environ[varname]) 51 52 antenvirons.update({ 53 'APAMA_HOME':parent.project.APAMA_HOME, 54 'APAMA_WORK':parent.project.APAMA_WORK, 55 'APAMA_LIBRARY_VERSION':getattr(parent.project, 'APAMA_LIBRARY_VERSION', ''), 56 'PATH':os.path.dirname(ant)+os.pathsep+os.getenv('PATH',''), 57 'JAVA_HOME':os.path.normpath(parent.project.APAMA_COMMON_JRE+'/..'), 58 'ANT_HOME':os.path.dirname(os.path.dirname(ant)), # needed so ant can locate its java classes 59 }) 60 61 # Merge in supplied environs, this will overwrite to user can set their own JAVA_HOME for instance. 62 if environs: 63 antenvirons.update(environs) 64 65 p = parent.startProcess(ant, 66 ['-buildfile', buildfile, 67 ]+(args or []), 68 environs=antenvirons, 69 timeout=timeout, stdout=dstdout, stderr=dstderr, displayName='%s %s'%(displayName, buildfile), 70 workingDir=outdir) 71 72 # exit code is a bit unreliable for ant, so grep stdout instead to find out if it worked 73 with open(dstdout) as f: 74 out = f.read() 75 if not 'BUILD SUCCESSFUL' in out: 76 parent.log.error('Ant execution failed for %s: \n%s'%(buildfile, out.strip())) 77 with open(dstderr) as f: 78 out = f.read() 79 if out.strip(): parent.log.error('%s'%out.strip()) 80 raise Exception('Ant execution failed for %s'%buildfile)
81