Selasa, 08 Februari 2011

Programmatically merge multiple LCA files using Apache Ant


A couple of colleagues needed a solution where they could take multiple unrelated LiveCycle ES applications already exported as LCA (LiveCycle Archive) files and programmatically merge them into a single LCA file. What’s the use case? Let’s say that you have a source repository of small LiveCycle ES applications that are re-usable. Then, based on a set of requirements, you need to build a new LiveCycle ES application that would include those re-usable smaller apps. Of course, you could just import each application individually into your LiveCycle ES development environment. But that’s not real exciting is it? And what is more exciting than building an Apache Ant build script to do some magic?


I created a build.xml file that will grab all LCA files stored in a src folder(see the build.properties file for configuration) and extract them into a work folder. This is pretty trivial since LCA files are just ZIP files that contain the application assets as well as a file called app.info. This app.info file is the key. It’s an XML file that describes the LiveCycle ES application and what operations should be executed when imported into a LiveCycle ES server. Here comes the tricky part…


To create a “merged” LCA file, I needed to parse each app.info file of the source LCA files, build a new master and inject the individual application descriptors from the source LCA files. Can you imagine my surprise when I realized that there was no existing Ant task that does this?!?! Yeah, right! OK, so I have to create a custom Ant task – great! Turns out, yet another trivial job. It was very easy to create my own custom Ant task and expose it in the build.xml. As a reference, I used this short tutorial. All I had to do at that point is write the Java code to load each app.info file into an XML DOM, extract the necessary nodes, build a new master app.info and import the previously extracted nodes. Piece of cake ;o).


Once I included my new custom Ant task into my build.xml, I just passed in the fileset reference that contained all of the app.info files and voila… I got my first merged app.info file. We just then drop that bad boy into the build folder, copy the asset folders that came with each LCA file in there too; and with one final zip ant task package up the combined LCA file.


Note: I also used the ant-contrib package because I needed a for loop in my build.xml in order to loop through each LCA file.


You must have Apache Ant installed and configured on your machine.


Attached Files:


Binary Distribution – Includes build.properties, build.xml, lib folder.


Source – Includes the Java source files for the custom Ant task.

Tidak ada komentar: