ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn McAllister <gl...@somanetworks.com>
Subject Re: Question about properties and ant2
Date Wed, 12 Sep 2001 13:16:19 GMT
Peter Donald wrote:

> On Wed, 12 Sep 2001 05:34, Claudio Corsi wrote:
> > This said, then how would I go about including a variable within the xml
> > file that is immutable and can be used throughout the xml file? If this
> > does not exist, can something like this be implemented? This can be for
> > ant1 or ant2.
>
> I think you mean mutable (ie changeable) not immutable. The only real way to
> do this today is via antcall and setting parameters in the antcall. Antcall
> actually creates a new Project instance and optionally populates it with
> property values again.

Actually, there is another way (and I'm not talking about using the XML ENTITY
stuff).

Since data types like patternset, fileset and path can now be defined inside of
targets with id's, you can create "generic" targets that make used of those
"named" data types.  Here's a simple, vastly truncated example:

<property name="build.base" value="build" />
<property name="src.base" value="src" />
<property name="src.java" value="${src.base}/java" />

<!-- usually its not a great idea to include your
     third-pary libs in your repository, but I'm doing
     this for illustrative purposes
-->
<property name="src.lib" value="${src.base}/lib" />

<target name="build">
  <mkdir dir="${build.classes}" />

  <javac srcdir="${src.java}"
         destdir="${build.classes}"
         debug="${debug}"
         deprecation="${deprecation}"
         optimize="${optimize}">
    <classpath refid="classpath" />
    <patternset refid="packages" />
  </javac>
</target>

<target name="build-my-subproject"
        depends="prepare-my-subproject,build" />

<target name="prepare-my-subproject">
  <property file="my-subproject.properties" />
  <property file="common.properties" />

  <patternset id="required_jars">
    <include name="log4j.jar" />
  </patternset>

  <patternset id="packages">
    <include name="com/some/company/myproject/*" />
    <include name="com/some/company/util/*" />
  </patternset>

  <path id="classpath">
    <fileset dir="${src.lib}">
      <patternset refid="required_jars" />
    </fileset>
  </path>
</target>

Contents of my-project.properties:

name=my-project
Name=My Project
version=1.0.0
debug=false
deprecation=false
optimize=true

Contents of common.properties:

build.dir=${build.base}/${name}
build.classes=${build.dir}/classes

So, every time you want to create a new subproject build you need to add two
targets (prepare-new-subproject, build-new-subproject), define a number of
patternsets and paths in the prepare- target, and add a new properties file.

The nice part about this layout is that you don't need near as many <antcall>
tasks; I find <antcall> to be a bit heavyweight for me.  The big place where you
do need antcall is in a build-all type target:

<target name="build-all">
  <antcall target="build-subproject1" />
  <antcall target="build-subproject2" />
  <!-- ... etc... -->
</target>

Hope that helps a bit.

Glenn McAllister
SOMA Networks, Inc.
Mime
View raw message