First Maven Alfresco baby wails

Some random note, mostly to myself, to remember, in some dark Maven time, how cool this technology is and that sometimes, at a certain point sure, you CAN have success stories with it.

For now, as I anticipated I’m just playing around with Alfresco core modules, to see how they fit with Maven and how tough can it be to port the full suite.
And you know what guys, on Friday, in just 4 hours I was able to have the core AND webscript framework completely building and tested with Maven (98% success rate).

I mean, it’s just a beginning, but considering that Webscripts are meant/designed to be deployed and integrated also outside of Alfresco, well, you understand the power of having only to add few dependency lines.

I’ll just drop the raw log of my operations, to give you a raw idea what can take for the m10n of an Ant project and how easy it can be if the source project is well maintained and tested.

Alfresco core mavenization (m10n):

  1. Checkout the core
  2. Refactor source tree (source/java –> src/main/java) and test tree (search with Eclipse for *Test.java AND Test*.java and refactor them to src/test/java)
  3. Refactor resources (find them in source –> src/main/resources) and test resources  (find them in source –> src/test/resources)
  4. Create pom via m2eclipse by adding Maven nature
  5. Add dependencies (analyze .classpath file as first step, then cycles of  ‘mvn compile’ and fix)
  6. TIP: Use mvnrepository.com  or even better if you m2eclipse is configured with a proper Nexus/Maven classes index you can directly search deps clicking on the red underline of the compilation error from Eclipse
  7. Install missing/uncertain dependencies on local repo:
    cd alfresco/workspace/alfresco-head/projects/3rd-party/lib/
    mvn install:install-file -Dfile=jta.jar -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1b -Dpackaging=jar
    mvn install:install-file -Dfile=jug-lgpl-2.0.0.jar -DgroupId=jug -DartifactId=jug-lgpl -Dversion=2.0.0 -Dpackaging=jar
    mvn install:install-file -Dfile=ibatis-2.3.4.726-patched -DgroupId=com.ibatis -DartifactId=ibatis  -Dversion=2.3.4.726-patched -Dpackaging=jar
  8. Add target Java 1.5 in Eclipse project and in Maven:
    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>1.5</source>
    <target>1.5</target>
    </configuration>
    </plugin>   
  9. Change line 47 in BaseTest.java
    // FIXME: Refactor this to take resource from classpath
    this.resourcesDir = System.getProperty("user.dir") + File.separator + "target" +
    File.separator + "test-classes" + File.separator;

Results:

Failed tests:
testJarSource(org.alfresco.config.xml.XMLConfigServiceTest)
Tests run: 54, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 2    6 seconds
[INFO] Finished at: Fri May 22 20:32:39 CEST 2009
[INFO] Final Memory: 8M/22M
[INFO] ------------------------------------------------------------------------

Well pretty cool if you consider only a couple of hours of work, 54 tests out of 55 working again 😉
That’s refactoring yeah!

Webscript Framework mavenization (m10n):

Pretty much the same steps, some dependency to deploy but basically the same trick.

Nice to note, under modules coupling POV, that the only intra-Alfresco dependency of the Webscript Framework is the Core, so that in another couple of hours I was able to run a

mvn clean install

on the Webscript frameowork project, with the following result:
Failed tests:
testRemoteStore(org.alfresco.web.scripts.TestRemoteStore)
testRemoteClient(org.alfresco.connector.TestRemoteClient)
Tests run: 16, Failures: 2, Errors: 0, Skipped: 0
[ERROR] There are test failures.
Please refer to /Users/mindthegab/Dev/alfresco/workspace/WebScript Framework/target/surefire-reports for the individual test results.
[INFO] [jar:jar]
[INFO] Building jar: /Users/mindthegab/Dev/alfresco/workspace/WebScript Framework/target/alfresco-webscript-framework-3.2.0-SNAPSHOT.jar
[INFO] [install:install]
[INFO] Installing /Users/mindthegab/Dev/alfresco/workspace/WebScript Framework/target/alfresco-webscript-framework-3.2.0-SNAPSHOT.jar to /Users/mindthegab/.m2/repository/org/alfresco/alfresco-webscript-framework/3.2.0-SNAPSHOT/alfresco-webscript-framework-3.2.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14 seconds

Ok needs refinement, and a proof of concept of integration in some webapp, but I feel already like all the “glue” power of Maven can be an additional enabler to such a feature-ful platform like Alfresco.
Suggest to stay tunes as I’ll definitely post more on this 🙂

Leave a comment

Leave a Reply

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