A magic buildfile gets information about the project it is
building from an index file. The following example shows
a minimal index file containing two projects. The
example is available under your merlin installation main
repository (sub-directory avalon/tools/demos) or alternatively
just download
demo.zip
.
index.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <system> <project basedir="gizmo"> <info> <group>demo</group> <name>gizmo</name> </info> </project> <project basedir="widget"> <info> <group>demo</group> <name>widget</name> </info> <dependencies> <include key="gizmo"/> </dependencies> </project> </system>
The index file show above contains two product defintions - one for gizmo and one for widget. The basedir attributes tells magic where to find these projects relative to the location of the index.
The following is the build file using for the gizmo project.
<?xml version="1.0" encoding="UTF-8" ?> <project name="gizmo" default="install" basedir="." xmlns:x="antlib:org.apache.avalon.tools"> <!-- Search for an index.xml file from current directory and upwards in the directory structures. --> <x:home /> <import file="${magic.templates}/standard.xml"/> </project>
Some important things to note in the above build file:
-
the ant project name
gizmo
is used as the default key to an entry in the index file (you can provide an alternative key by declaring the property ${project.name} before the home declaration) -
The
xmlns:x="antlib:org.apache.avalon.tools"
declaration tells ant that we are using "x" as the short name for the antlibantlib:org.apache.avalon.tools
. -
The default target "install" is a target declared in the
imported buildfile
${magic.templates}/standard.xml
. -
The
<x:home />
triggers the loading of the index file located in the current directory OR in any ascendent parent directory, i.e. the file system will be scanned upwards in the directory structure, and from this the construction of the project model that contains version information, dependencies, etc. -
The
<import file="${magic.templates}/standard.xml"/>
tells ant to import a template build file from the ${magic.templates} directory. The ${magic.templates} directory defaults to ${magic.home}/templates. The ${magic.home} property defaults to the value of the environment variable MAGIC_HOME (if defined) otherwise it will return${user.home}/.magic
-
The file
${magic.templates}/standard.xml
contains several standard build targets.
You should have a general idea of the structure of an index based on the information described above. While there are several notions we have not discussed yet (external resources, plugins defintions, index importing, etc.) we will move on to actually building widget and gizmo - described under the next subject - My First Spell.