Tuxitecte

mercredi 28 avril 2010

Maven + Alfresco : Delivery and Assembly


Hello everyone!

It is time to talk about the delivery format of your project. You tell me, he use for many post AMP format and now he wants to give us something else? Yeap it's true...!

Depending on your projects, your distribution of roles, your teams and your business practices, the delivery format can be simple or very very complex!

Take the classic case, on the one side we have a development team and in the other side we have an operation (production) team. The first one is responsible for creating the product, the other is in charge of installing the product and verify that it works throughout its lifetime.

The question: What is the exchange format of product between these two teams?
Ps: we will not consider here all the documentation from the production team ...

Let's make a list of possible cases:

  • AMP(s): For the development team is the simple format. Indeed it is the output format of our project! So you have just to get AMP file and send it! Of course if our project consists of several AMPs, we will send all AMPs. In this case, the production team is responsible for generating the WAR application using the script provided by Alfresco.
  • A WAR: Here the development team is responsible for creating the war. They have to integrate different modules in the default Alfresco war. The production team have to simply install the application.
  • AMP + WAR: In this scenario, the production team want to have the application and AMPs.
  • Other: Here you can invent anything that goes through your head. If you work in big projects, or in a large size companies, I think you have very beautiful examples!
As you can see, examples are not lacking! It is rather the opposite. The question :
How can we create these new delivery formats in our AMP project ?

The idea as usual is to run a Maven command and wait for the generated file(s). Never forget that the developer is supposed to be lazy ^ ^.

In lines below, I will present two approaches to generate anything other than your AMP. These approaches are based on a new project called war-alf-osecm.

Note: This approach is not very consistent with the philosophy but Maven does the work desired.

Creating a new project AMP

Defining Structure
Create a directory with the name: alf-war-osecm and add a pom.xml with value below

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
fr.opensourceecm
alf-war-osecm
pom
0.1
Alfresco AMP Open Source ECM
Open Source ECM - Extension




Integrating the tool into a repository

In this project, we will use AlfrescoModule Management Tool . This module is available in the bin directory of Alfresco standard installation . It is also available here: http://wiki.alfresco.com/wiki/Community_Edition_file_list_3.3.
So initially, we will install this file in our maven repository with the command:

call mvn install:install-file -Dfile=alfresco-mmt.jar -DgroupId=org.alfresco.sdk -DartifactId=mmt -Dversion=3.3 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true


Note : We perform this command in the directory where Alfresco module management tool file is.
Due to this integreation, It will be possible to find it through the classic mechanism of dependency .

Create a new Alfresco WAR
Now, as the title suggests, I want to generate a WAR with all AMPs. It will integrate all AMPs in a WAR Alfresco. This process will be divided into 4 parts.
  • Setting Properties: In this part, we will initialize the properties that we used during other parts.
  • Import pre-requisite: We will install Alfresco war and tool into our working directory.
  • Import of AMP: In our working directory, we will create a subdirectory that will serve to contain all AMPs to integrate.
  • War Generation : Here, we will launch a command line to integrate AMPs
  • (Optional) Install war in maven repository: After generation, you can optionally add the generated war in our maven repository.
Setting Properties
We will define four properties
  • Work.dir: Working directory
  • Amps.dir: AMP directory
  • Mmt.jar: Module Management Tool filename
  • Alfresco.war: Alfresco war filename



livraison
amps
mmt.jar
alfresco.war




Import pre-requisites
Via the plugin maven-dependency-plugin we will use the goal copy during the prepare-package phase. To simplify, we want to copy a set of dependencies (alfresco.war and tool) in our working directory.


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


war-copy-requisites
prepare-package

copy




org.alfresco.sdk
alfresco-community-war
3.3
war
${project.build.directory}/${work.dir}
${alfresco.war}


org.alfresco.sdk
mmt
3.3
jar
${project.build.directory}/${work.dir}
${mmt.jar}









Import AMP
In this stage, we will add a dependencies block in our pom.xml. In our case, dependencies contains 2 dependencies :
  • fr.opensourceecm:alf-osecm-am:amp:0.0.5
  • org.alfresco.sample:SDK-CustomWizard:amp:1.0

Our pom.xml looks like



fr.opensourceecm
alf-amp-osecm
0.0.5
amp


org.alfresco.sample
SDK-CustomWizard
1.0
amp




Then, we continue using maven-dependency-plugin. We will realize the goal copy-dependencies in the phase of prepare-package. More simply, we want to copy all MPAs (defined in length) in a subdirectory of work amps.dir ().



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


war-copy-amp
prepare-package

copy-dependencies


amp
${project.build.directory}/${work.dir}/${amps.dir}
false
true
true






War Generation
Via the plugin exec-maven-plugin, we will realize the goal exec during the package phase. In other words, we want to achieve the same behavior as apply-amps.bat file (or .sh) but via Maven.



org.codehaus.mojo
exec-maven-plugin
1.1


war-create
package

exec




java

-jar
${project.build.directory}/${work.dir}/${mmt.jar}
install
${project.build.directory}/${work.dir}/${amps.dir}
${project.build.directory}/${work.dir}/${alfresco.war}
-directory






Now it is possible to run the command


mvn clean package



You can now find in your work.dir a new alfresco.war containing all AMP dependencies defined in our pom.xml.

(Optional) Install the war locally
If you want to install this war in your local repository (and thus be able to create dependencies for testing or integration purposes), here is the configuration to add to your build phase:


org.apache.maven.plugins
maven-install-plugin
2.3


war-install
install

install-file


${project.build.directory}/${work.dir}/${alfresco.war}
${project.groupId}
${project.artifactId}
${project.version}
war
test
true
true






With the command

mvn clean install


you can install your new war. Of course, you can change various settings to suit your needs ...

Note: You can do the same deploy phase if you change some parameters... ^ ^


Create a custom delivery format
Now we'll look at creating a custom delivery format. In my case, I wish
  • Create a zip file containing
  • A root folder : groupId.artifactId
  • A sub-folder amps containing my amps
  • A sub-folder application containing alfresco.war (with the amp already include)

To do the job, I'll use maven-assembly-plugin. This plugin is used to create custom distribution formats. Configuration of this plugin is done in 2 steps:
  • Create a description file
  • Adding configuration in pom.xml

Create a description file

This description file defines the expected result ie what are the directories to create, file formats, rights, encoding ... We can actually define a lot of parameters!

In our case, we will create osecm-assembly.xml in alf-war-osecm\src\assembly directory. This file contains the following configuration:


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
production

zip

${project.groupId}.${project.artifactId}.${project.version}


target/${work.dir}
unix
/application

${alfresco.war}





/${amps.dir}

org.alfresco.sample:SDK-CustomWizard
fr.opensourceecm:alf-amp-osecm







As you can see, it takes the configuration expected in my requirements.

Adding to the pom.xml
Now we must declare in the pom.xml this new file. So we add maven-assembly-plugin with the configuration below


maven-assembly-plugin


src/assembly/osecm-assembly.xml






Start assembly
Finally, I can run the command :

mvn clean assembly:assembly



This command assemble my custom distribution format. In the target directory, you can find your custom file called : alf-war-osecm-0.1-production.zip ready to be sent!

Note: This plugin may be greedy in memory. To resolve this problem increase values in MAVEN_OPTS environment variable.
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 commentaires: on "Maven + Alfresco : Delivery and Assembly"