Alfresco – Version Stamp Your AMP

I always find myself renaming AMP files after building them – I add the module version to the name. Being relatively lazy I decided to see if I could have Alfresco’s ANT build do this for me.

After a bit of trial and error I figured it out and created an ANT macro to do it for me.

I put my macro in a separate file called abstractive-macros.xml.

It has 2 parameters:

  1. modpropsdir is the directory containing the file. This is where we read the module version. It’s probably already defined in your under a property called
  2. ampnameproperty is the NAME of the property that contains the AMP file name. We just want the name of the property (not its value) because we want to update the property itself so anything else that uses it will have the new name.

The macro:

  • pulls in the contents of
  • pulls the extension from the amp file name
  • gets the “module.version” from
  • builds a new amp file name that includes the version

It turns out you can use javascript within an ANT script – I didn’t know that. You can also use all kinds of other scripts such as groovy, ruby, jython, judoscript, etc.

Here’s the complete macro xml.


<project name="abstractive-macros">

   <macrodef name="versionamp" description="Appends the module version to the amp file name">

      <!-- modpropsdir is the VALUE of the -->
      <attribute name="modpropsdir" />

      <!-- ampnameproperty is the NAME of the property
           and its value will be updated to include the module version -->
      <attribute name="ampnameproperty" />

        <!-- append module version to amp file name -->
        <property file="@{modpropsdir}/"/>
        <script language="javascript"> <![CDATA[
          amp = project.getProperty("@{ampnameproperty}");
          title = amp.substring(0, amp.indexOf(".amp"));

          version = project.getProperty("module.version");
          project.setProperty("@{ampnameproperty}", title + "_" + version + ".amp");
        ]]> </script>

The only change to build.xml is to include our new macro xml file.


  <import file="macros.xml" />
  <import file="abstractive-macros.xml" />
  <import file="projects.xml" />

And in projects.xml we make the call to the macro. This is done in the package-MYMODULE-extension target. I pass it the path to module properties and the NAME of the property that contains the amp file name.


  <target name="package-MYMODULE-extension" depends="package-MYMODULE-jar">

    <versionamp modpropsdir="${}"
      ampnameproperty="" />

    <zip destfile="${dir.module.MYMODULE.dist}/${}" update="true">
      <zipfileset file="${}/" />
      <zipfileset file="${dir.module.MYMODULE.dist}/${}" prefix="lib" />
      <zipfileset dir="${dir.module.MYMODULE}/${}" prefix="lib" />
      <zipfileset dir="${dir.module.MYMODULE.config}" prefix="config">
        <exclude name="**/" />

And that’s all there is to it.  So if:

  • your contains module.version=1.10
  • in your your

and you run the package-MYPROJECT-extension target it will generate an amp called MYPROJECT_1.10.amp.

This entry was posted in Alfresco, Alfresco Share, ECM by tim.frith. Bookmark the permalink.

About tim.frith

Alfresco Certified Engineer

Senior ECM Consultant
Tim holds a diploma in Computer Systems Technology from Camosun College as well as a Bachelor of Commerce Degree with a Finance specialization from the University of Alberta. He has over 10 years of experience developing web applications with Java as well as extensive database development experience with Oracle, IBM DB2, MS SQL Server, and MySQL.

In recent years he has focused on Enterprise Content Management, with specific training and experience in Alfresco's content management suite.

And finally, Tim is a strong believer that the Edmonton Oilers will soon reclaim their rightful place at the top of the hockey world. Yes, Stanley will once again come to town.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>