ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Inger <ma...@sedonacorp.com>
Subject Re: Need Coding Standards
Date Tue, 07 Aug 2001 16:53:10 GMT
Sivaprasad.Kancherla@itsindia.com wrote:

>Are there any published (although unofficial) coding standards for Ant
>build.xml files?
>
>I am using Ant for the first time and am confused about how to arrange
>different top level elements under project tag. For example should I keep
>all 'target's togther and 'property's together or mix them up for
>readability etc.
>
>- Siva
>
>

As a general principle, i tend to keep all global property definitions, 
at the top of
the file.  This includes any patternsets, filesets, path's, etc.... that 
can be built at
startup.  Then "private" (non-advertised targets), then the public 
targets.  This is
not to say that this is the only way, but i think it makes sense to do 
it that way.
Here is the general format of my build.xml files.

<?xml version="1.0" encoding="iso-8859-1"?>

<project name="Project" default="usage" basedir=".">
 
  <taskdef name="sometask" class="some.package.SomeTask" />
  <property resource="build.properties" />
  <property name="install.dir.bin" value="${install.dir}/bin" />

  <target name="private_target">
  ...
  </target>

 <!-- *********** PUBLIC TARGETS **********  -->

  <target name="install">
  ...
  </target>

  <target name="usage">
  ...
  </target>

</project>



You could even take it a step further, and put all your private targets
in a seperate xml file, and call it using the "ant" task.  You could either
pass it parameters or relying on properties that were set in the calling
file.  So, not only does this hide targets from people looking at your xml
file, it also forces them to explicity use the -buildfile option of ant to
call a non-public target.  Thereby making it more annoying for them to
do.


-- 
Matt Inger (matt.inger@sedonacorp.com)
Sedona Corporation
455 S. Gulph Road, Suite 300
King of Prussia, PA 19406
(484) 679-2213
"Self-respect - the secure feeling that no one,
 as yet, is suspicious." -H.L. Mencken 




Mime
View raw message