DPML
Declaring Type Production by a Project
HomeUtilitiesStationMetro
Using Type Production Statements

A project definition can contain multiple <type> statements within an enclosing <types> element. The direct impact of a type declaration is the automatic definition of several Ant project properties dealing with the local directory and filenames of produced types that follow a single convention. This convention states that all resources (files, etc.) produces by a build shall be placed in a directory named ${basedir}/target/deliverables/[type]s/[name]-[version]. The convention also requires that resources declared within a project defintion should be published to the local system cache for potential usage by other projects (taking into account the potentially customizable layout employed by the cache).

Type Related Properties

The following table summarises the type related properties automatically established by Depot.

project.deliverable.[type].path The path of the resource relative to the project basedir.
project.deliverable.[type].dir The path of the enclosing directory relative to the project basedir.
project.cache.[type].path The path of the resource relative to the system cache.
project.cache.[type].dir The path of the enclosing directory relative to the system cache.
index.xml

The index.xml file shown below includes the addition of a type product statement <type id="jar"/> indicating that the project produces a jar file. As such, Ant project project properties will be created for the local and cache-based locations of enclosing directories and resource paths. These properties can be used within a build file to simplify the handling of file names and locations.

<?xml version="1.0" encoding="ISO-8859-1"?>
<index xmlns="dpml:library">

  <project name="demo" basedir=".">
    <properties>
      <property name="location" value="New York"/>
      <property name="message" value="Hello from ${user.name} in ${location}"/>
    </properties>
    <types>
      <type id="jar"/>
    </types>
    <filters>
      <filter token="MESSAGE" value="${message}"/>
    </filters>
  </project>

</index>
build.xml

The following build file uses standard properties concerning target directory location, strc file location, compiled classes directory, final jar deliverable naming, and cache path to construct and publish a jar file.

<project name="demo" default="install">

  <target name="clean">
    <delete dir="${project.target.dir}"/>
  </target>

  <!--
  Copy the src content to the target/build/main directory with filtering
  applied and compile the resulting source files into the target/classes/main
  directory.
  -->
  <target name="build">
    <mkdir dir="${project.target.build.main.dir}"/>
    <copy toDir="${project.target.build.main.dir}" filtering="true">
      <fileset dir="${project.src.main.dir}"/>
    </copy>
    <mkdir dir="${project.target.classes.main.dir}"/>
    <javac srcdir="${project.target.build.main.dir}" 
      destdir="${project.target.classes.main.dir}"/>
  </target>
  
  <!--
  Package the compiled classes into a jar file and place the result in the 
  target/deliverables/jars directory.
  -->
  <target name="package" depends="build">
    <mkdir dir="${project.deliverable.jar.dir}"/>
    <jar destfile="${project.deliverable.jar.path}" 
      basedir="${project.target.classes.main.dir}"/>
  </target>

  <!--
  Copy the jar file to the system cache.
  -->
  <target name="install" depends="package">
    <mkdir dir="${project.cache}/${project.cache.jar.dir}"/>
    <copy file="${project.deliverable.jar.path}" 
      toFile="${project.cache}/${project.cache.jar.path}"/>
  </target>

</project>
Building the project ..
$ cd tutorials\tooling\simple\types
$ build

-------------------------------------------------------------------------
demo#SNAPSHOT
-------------------------------------------------------------------------

build:
    [mkdir] Created dir: D:\dpml\tutorials\tooling\types\target\build\main
     [copy] Copying 1 file to D:\dpml\tutorials\tooling\types\target\build\main
    [mkdir] Created dir: D:\dpml\tutorials\tooling\types\target\classes\main
    [javac] Compiling 1 source file to D:\dpml\tutorials\tooling\types\target\classes\main

package:
    [mkdir] Created dir: D:\dpml\tutorials\tooling\types\target\deliverables\jars
      [jar] Building jar: D:\dpml\tutorials\tooling\types\target\deliverables\jars\demo-SNAPSHOT.jar

install:
    [mkdir] Created dir: D:\system\dpml\data\cache\jars
     [copy] Copying 1 file to D:\system\dpml\data\cache\jars

BUILD SUCCESSFUL
Total time: 1 second

$
        
Summary

This tutorial has demonstrated the benefits gained from standard and type-derived property values. These benefits really come down to the usage of a standard project layout, naming conventions, and shared repository. Given these resources combinaed with support for programatic access to a project defintion - the logic next step is the automation of common taks such as jar file production. In the next tutorial we introduce the usage of a imported build template that handles the establishment of a number of tasks that are project-defintion-aware.