ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Stewart" <MStew...@mgtplc.com>
Subject Re: Calling a cmd batch file from Ant
Date Wed, 28 May 2008 14:25:44 GMT
I have used the following to include the components specific to the
clients which I am building the code for.

There is the main build.xml file which then opens a file called
componentnames.txt, this file is opened and the component name extracted
and used to execute the appropriate build.xml for the conmponent. In
this way components can be treated like an object in that the component
"knows how to build itself".

Adding components is then achieved by adding the component name in to
the text file and providing the build.xml file for the component. The
main build file does not have to be modified in any way to add the new
functionality to the build. The target below is called supplying the
${client.name} and a path to the root directory e.g. C:\Build in the
${component.path} property.


	<!-- This target calls the build.xml for each of the client
specific components -->	
	<target name="BuildComponents" description="Automatic build of
components specified in the file componentnames.txt in the client
directory." >

		<!-- load the componentnames file for later use -->
		<loadfile
srcFile="${component.path}/${client.name}/componentnames.txt"
property="componentnames" failonerror="false" />
		
		<ac:if>
			<isset property="componentnames" />
			<ac:then>

			<!-- extract the component file names from the
/componentnames.txt file -->
			<ac:for delimiter="${line.separator}"
param="componentname" list="${componentnames}">
				<sequential>
					<!-- Call the localdeploy for
component files -->
					<ant
antfile="${component.path}/${client.name.root}/@{componentname}/build/build.xml"
target="LocalDeploy" inheritAll="true" >
					</ant>
					<ac:if>
						<isset
property="RemoteDeployComponent" />
						<ac:then>						
							<!-- Call the
remotedeploy for component files -->
							<ant
antfile="${component.path}/${client.name.root}/@{componentname}/build/build.xml"
target="RemoteDeploy" inheritAll="true" >
							</ant>
						</ac:then>
					</ac:if>
				</sequential>
			</ac:for>		
			
			</ac:then>
			<ac:else>
				   <echo message="no components to
deploy." />
			</ac:else>
		</ac:if> 
		
	</target>

I've attached a screenshot which shows the directory structure, the
main build.xml is in the Build\build directory and extracts the
componentnames.txt file from the component\${client.name} directory
which in the case of client3 contains:

WebSelfService
WebService


These are then used to create the path to the component directory with
the build.xml e.g. C:\Build\component\client3\WebSelfService\build, this
is then used to call to the LocalDeploy and RemoteDeploy targets as
above. 

Note that I used failonerror="false" when opening the
componentnames.txt file as not all clients have components and the build
would fail if the file didn't exist.



Mike S.

>>> chris.green100@googlemail.com 28/05/2008 08:37:03 >>>
I am calling a dos batch file from an Ant script using the following
code :-

<property name="dos" location="c:/windows/system32/cmd.exe"/>


<exec executable="${dos}" dir="c:/build/">
          <arg value="CommonCommponent.bat"/>
</exec>

On the assumption that I get the Microsoft Windows Copyright info
appear, I
assume the above commands are running ok. The only trouble is, the
contents
/ commands in the batch file don't seen to get executed.

Batch file contents are :-

set component=common
ant -f %build.dir%/component.xml

Any help would be gratefully received.

Chris

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


Mime
View raw message