Tuxitecte

mercredi 28 avril 2010

Maven + Alfresco : Multi-AMP relationship



Hello World!

This time I'll try to explain multi-AMP relationships and how they can be managed with Maven and Alfresco...



Introduction

The problem is as follows:
In a multi-AMP project, how we organize those relationships in our Maven project(s) ?

Suppose we want to create a project with 3 AMPS: A, B, C

Above all, what are the relationships between these three AMPS? Are they independent, interdependent ? What are relations induced?

Then, what is the delivery format of our application? Is it a WAR, a single AMP, a set of AMP, a particular format of delivery...

According to the answers of each question, we have to create different policy! and of course, we have to create different configuration of Maven projects!

In general, I identify several use cases.

  • Simple relationships: In other words it is the same dependency that we've seen since we began our projects. In our case, modules A, B and C are independent, but our production server needs these three AMP to match our user's needs. For example, we want to integrate Alfresco RM module, SharePoint module and our own module including our personalization.
  • Dependencies (weak and strong): In this case, one module needs another module to work. A simple example is the association that may exist between a model of data and actions associated with this data model. If the model doesn't exist and if is not installed then B can't work. If B is changed so it changes the behavior of A.

How to define (and test!) these relationships in our project?

Simple relationships

First, we will use our historical alf-amp-osecm module.

Currently, our module has only dependencies to libraries already present in the Alfresco war. There are no problem because when we start our jetty server with Alfresco war.

But now I want to test my module with the presence of another modules.

Today for example, I'll take the module SDK-TaggingSample (previously created - cf. Post here). The idea is to
  • add SDK-TaggingSample module into Alfresco.war,
  • package my alf-amp-osecm module
  • run jetty to test the intregation and interaction between these modules

To add SDK-TaggingSample module, we will modify the pom.xml of alf-amp-osecm and the declaration below between dependencies tags in the webapp Profile.


org.alfresco.sample
SDK-TaggingSample
amp
1.0



At this stage, we might say, it's good ! We can launch our application with the maven command:

mvn clean integration-test -P webapp,clean-jetty -DskipTests=true


and we will have an Alfresco started with our two modules. Well in fact no... That would be too easy!

The AMP format is a custom format which is not well recognized by Maven and related plugins. Maven recognized this format thanks to maven-amp-plugin. But here we add an AMP dependency! The question is : Does Maven know how to integrate this AMP into exploded war necessary to jetty server ? The answer is obviously NO!

The solution lies in the declaration of a new plugin: maven-dependency-plugin. This plugin as its name suggests can manipulate dependencies and artifacts and therefore AMP! We will configure this plugin to use our dependency and install AMP into our exploded war.

How ? We have to add the configuration below. It has to be incorporated in webapp profile (in my case, it is now in the project alf-sdk. re-factoring required! Nevertheless the declaration of dependency is in my pom.xml)


org.apache.maven.plugins
maven-dependency-plugin


unpack-amps
process-resources

unpack-dependencies


amp
${build.directory}/${webapp.name}
META*





org.alfresco.maven.plugin
maven-amp-plugin
3.0.2





Note that this plugin will take all the dependencies of AMP type and will execute the goal: unpack-dependencies in the directory $ (build.directory) / $ (webapp.name). In other words, it will install AMP as would (almost) Alfresco Module Management Tool.

Next, we must add a testRessource block in webapp Profile .


true
.

module.properties

alfresco/module/${project.groupId}.${project.artifactId}



This block is necessary when we want to integrate several AMP in a war (which is our case here).

Now we can run the command:

mvn clean integration-test -P webapp,clean-jetty -DskipTests=true


and check (after a few minutes) our working AMPS!

Technology is beautiful sometimes ;o)

Dependencies

Now we will focus on dependencies. In this case, I don't want my Alfresco app starts if my module doesn't have all necessary dependencies. If this case happens, we would have an unstable application that could damage data! (I obviously don't wish it...).

How to define these strong dependencies between my modules?

Due to significant changes in my code, I want to create a strong link between my alf-amp-osecm and SDK-TaggingSample. To do this, there is a mechanism defined in the AMP and available via module.properties (located at the root of our project).
At the end of this file, simply add the line below to create a dependency:

module.depends.org.alfresco.sample.SDK-TaggingSample=0.1-*


Note the simple formalism:
  • Module.depends: to define a dependency module
  • groupId.artifactId or module name : to identify the module
  • XX - YY: To determine version range of the module to be taken into account (between XX and YY). In our exemple, our module depends on SDK-TaggingSample from version 0.1. (Note the possibility to use wildcard character that means any)
For more information: wiki.alfresco.com

You can now start the application via this Maven command:

mvn clean integration-test -P webapp -DskipTests=true


As you can see, nothing change! It's good but what we would like here is to verify that our mechanism works well. For this you have two choices.
  • Change the version number in the file module.properties. For example: module.depends.org.alfresco.sample.SDK-TaggingSample = 99.99-*
  • Remove SDK-TaggingSample dependency in dependencies block in our pom.xml.

In both cases, restart the application and you will see in the console a nice stacktrace! It prohibits that you start the application if the dependency is not respected!


That's all for today!

Mavenize well!

PS :
alf-sdk sources are available here:
http://www.box.net/shared/exremqsr0m



alf-amp-osecm sources are available here:
http://www.box.net/shared/dzige0nchr


Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 commentaires: on "Maven + Alfresco : Multi-AMP relationship"