Support

Forums

Contact Me

Posts Tagged 'maven'

MAVEN

Mars Atmosphere and Volatile EvolutioN (MAVEN) is a planned space exploration mission to send a space probe to orbit Mars. [http://en.wikipedia.org/wiki/MAVEN]

Configuring TeamCity, Maven for PHP for Joomla continuous build

apache_maven

Doxygen phpDocumentator phpunit-logo teamcity512 maven4php

Maven for PHP uses the power of Maven for building, reporting on and creating documentations of PHP projects. It adapts the Maven build lifecycle to the PHP world while fully supporting PHP 4 and PHP 5. PHP for Maven uses PHPUnit for unit testing and doxygen for creating the api documentation.
Use a PHP library project to create a library that can be used by other PHP libraries or PHP web projects. Use a PHP web project to create a standalone web project.

So I quickly describe what I did install on my root server (OpenSuse 11.X)

My Objectives: being able to build all my Joomla! component using best agile development practices

“Specific tools and techniques such as continuous integration, automated or xUnit test, pair programming, test driven development, design patterns, domain-driven design, code refactoring and other techniques are often used to improve quality and enhance project agility.”

Read more: Configuring TeamCity, Maven for PHP for Joomla continuous build

Apache Maven 3 Cookbook Review

Thanks to Packt Publishing for having sent me this book to review. I will publish a review in the next coming days

  • Grasp the fundamentals and extend Apache Maven 3 to meet your needs
  • Implement engineering practices in your application development process with Apache Maven
  • Collaboration techniques for Agile teams with Apache Maven
  • Use Apache Maven with Java, Enterprise Frameworks, and various other cutting-edge technologies
  • Develop for Google Web Toolkit, Google App Engine, and Android Platforms using Apache Maven

Apache_Maven3_Cookbook

You may also consider reading all my articles related to Apache Maven

When Joomla! meet Maven for PHP

apache_maven

joomla logo vert color

  I will quickly describe in this post how you can code your component/plugins/modules against a specific version of Joomla! with no effort using Maven for PHP.

The trick I made is to package the whole Joomla distribution in a jar file, and add a Maven dependency to the project. As Joomla, PHPUnit, or any other 3rd party is not a set of class packaged in a jar, the brilliant idea of Maven for PHP is to unpack all these dependencies in the target/phpinc directory automatically AND concatenating this directory to the php setting include_path during compile and test phase. You can do the same using the command line by running:

php -d include_path=

That’s also why, It is very important to not put anything from this directory under version control (add a cvs.ignore or svn properties svn:ignore) as it contains dependencies that have no reason to be put under version control in Maven paradigm (they have to reside in a Maven repository)

So I create a new zip file joomla-1.5.10.jar with a directory inside named ‘Joomla’ that contains a standard binary distribution…this jar is published in artifactory with a groupid org.joomla (arbitrary chosen by me)

Read more: When Joomla! meet Maven for PHP

List conflicting dependencies in the Maven reactor

apache_maven

The Maven Dependency Plugin among other things include a dependency:analyze-duplicate

The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

This Apache Maven plugin is really feature rich and provide a lot of interesting goals:

Read more: List conflicting dependencies in the Maven reactor

Get a command prompt on any Eclipse project

eclipse 

A very little trick that allow you to quickly run any operation involving a DOS command on an Eclipse project. Go to the external launcher, and create a new configuration.

This trick may be useful for running your Maven set of command without any dependencies to M2Eclipse.

 

 

Read more: Get a command prompt on any Eclipse project

Break Maven build when there is a dependency conflict

apache_maven_thumb

Scenarios

  • You want to control Maven during dependency resolution and break the build if some conditions are not met,
  • You want to detect dependencies conflict early during the build,
  • You want to avoid anybody in your team to use the dependency x in the version y

This is where the Maven Enforcer Plugin will assist you:

The Enforcer plugin provides goals to control certain environmental constraints such as Maven version, JDK version and OS family along with many more standard rules and user created rules.

Add in your pom.xml the following to configure the plugin

Read more: Break Maven build when there is a dependency conflict

Failed opening required PHPUnit/TextUI/TestRunner.php in Maven For PHP

apache_maven

This issue has turn me upside down a long time. In fact in the official Google Group http://groups.google.de/group/maven-for-php/ I was not the only one to have this issue.

I did try the following, and it is always good to check first

  • Checking PHP version,
  • Starting Maven with -X for having more debug information
  • Testing it in Eclipse + M2Eclipse on windows, was working there,
  • Comparing calculated PHP include path on Windows and Linux: they were identical in this case

Only my Linux box was not working. . .(http://teamcity.waltercedric.com)

After that I did materialize the eclipse project of maven-php-plugin and even built a custom version that I’ve deployed without any effort to my Artifactory (http://maven.waltercedric.com)

And what is the solution?

it my server configuration and paranoia :-)

open your php.ini, ideally the right one, don’t put your server at risks: You may have many under Linux, especially if you use plesk or cpanel 

  • cli at /etc/php5/cli/php.ini
  • apache2, /etc/php5/apache2/php.ini
  • fastcgi at /etc/php5/fastcgi/php.ini

location most of the time

/etc/php5/cli/php.ini

and add the directory where your build server make a checkout...

; open_basedir, if set, limits all file operations to the defined directory
; and below.  This directive makes most sense if used in a per-directory
; or per-virtualhost web server configuration file. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
open_basedir = /www/vhosts:/tmp:/xxxx/yyyy/

Next step is to put Joomla! 1.6 and all their PHPUnit tests a run along with Selenium. May also need to  patch Maven for PHP to better support Tests reporting like Surefire.

Apache Maven Cargo deploy with Tomcat 7

apache_maven

cargo-banner-left

Following the post about Deploy to Tomcat 6 using Maven, here is a ready to use example with the main differences explained in the table below

  Tomcat 7 Tomcat 6
containerId <containerId>tomcat7x</containerId> <containerId>tomcat6x</containerId>
Url of Tomcat manager <cargo.remote.uri> <cargo.tomcat.manager.url>
example http://host..com/manager/text/ http://host..com/manager/
tomcat-users.xml

<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui,manager-script"/>
</tomcat-users>

<tomcat-users>
  <role rolename="manager"/>
  <user username="admin" password="admin" roles="manager"/>
</tomcat-users>

And finally a snippet of an Apache Maven pom.xml ready to use in a profile, so you can reuse this profile like a method call

<profile>
 <id>deployTomcat</id>
<activation>
  <activeByDefault>false</activeByDefault>
</activation>
<build>
 <plugins>
    <plugin>
     <groupId>org.codehaus.cargo</groupId>
     <artifactId>cargo-maven2-plugin</artifactId>
     <version>1.1.0</version>
    <configuration>
     <wait>true</wait>
     <container>
      <containerId>tomcat7x</containerId>
      <type>remote</type>
     </container>
     <configuration>
      <type>runtime</type>
      <properties>
       <cargo.remote.uri>
         ${tomcat.url}
       </cargo.remote.uri>
       <cargo.remote.username>
          ${tomcat.user}     
       </cargo.remote.username>
        <cargo.remote.password>
          ${tomcat.pwd}
        </cargo.remote.password>
      </properties>
      </configuration>
      <deployer>
       <type>remote</type>
       <deployables>
       <deployable>
        <groupId>${deploy.groupid}</groupId>
        <artifactId>${deploy.artifactid}</artifactId>
        <type>war</type>
        <properties>
         <context>${deploy.context}</context>
        </properties>
       </deployable>
      </deployables>
     </deployer>
    </configuration>
    <executions>
     <execution>
      <id>verify-deploy</id>
      <phase>pre-integration-test</phase>
      <goals>
       <goal>deployer-undeploy</goal>
       <goal>deployer-deploy</goal>
      </goals>
     </execution>
    </executions>
    </plugin>
 </plugins>
</build>
</profile>

Place as many profiles as you have machine to deploy in settings.xml and declare some variables as properties, as shown below:

<profile>
 <id>serverA</id>
 <activation>
    <activeByDefault>false</activeByDefault>
 </activation>
 <properties>
    <tomcat.url>http://host.com/manager/text</tomcat.url>
    <tomcat.user>admin</tomcat.user>
    <tomcat.pwd>admin</tomcat.pwd>
    <!-- these properties must be defined
       as system property or -D -->
    <!-- - deployable.artifactid:
         artifactId of web application to be deployed -->
    <!-- - deployable.context: web context name -->
 </properties>
</profile>

So you can run, and traget multiple host by just exchanging the name of the profile serverA to something else.

mvn integration-test –PdeployTomcat,serverA
   –Ddeployable.artifactid=demo
   -Ddeploy.groupid=com.mycompany
   –Ddeployable.context=showcase

Speeding up Apache Maven Builds

apache_maven

The obvious things to do first in no particular order

  • Use a better build server, CPU power is cheap today,
  • Throw more memory, as Maven run in a JVM the more you have the better it may behave, you may want also to increased the perm gen space,
  • Use the latest  version of JVM!
  • Switch as many plugins as possible as long as there are not needed in the main build loop: Use profile to modularize your build and trigger some additional build/reporting plugins when needed. You want your build to be fast to provide fast feedback to your developers.
  • Optimize your test cases, some may take longer than other, use @BeforeClass or Lazy initialization to cache some heavy to create objects,
  • Tune the garbage collector according to your build behavior, number of CPU core:  use parallel garbage collector for example,
  • Carefully review your dependencies as the less Apache Maven has to load while building the faster it will get.
    • Are they all needed?
    • No duplicates dependencies?
    • Do you miss some <exclusions>? are all these transitive dependencies to your 3rd party needed?
    • No dependencies cycles? check the order in reactor. A developer should understand, and not be surprised by  the order of the modules calculated by Maven (as long as you have layers in your software, you expect some modules to be build before some others) .
  • Review ALL logs files
    • The one created by Maven to avoid any warnings and
    • All your application logs (do you log too much data during the build?)

Read more: Speeding up Apache Maven Builds

Technology management using artifact life cycles

I forgot to blog about this presentation at JAZOON 2008, but I did never forget the added value of this plugin. It is not currently in Apache Maven  core but will for sure find its way as an official plugin one day, since it solve elegantly a common problem: technology management

Maven does not know the concept of an artifact life cycle. Such life cycle status information would allow to extend the dependency management in a new dimension. One could declare whether certain dependencies are actually allowed/forbidden/restricted to be used in a project, enabling effective technology management.

Currently a plugin is available to achieve this goal:The AssertDepend plugin. It work by adding metadata, additional xml files in artifact group directory.

The AssertDepend plugin is a Maven extension to perform effective technology management. The plugin checks at build time against lifecycle states defined in metadata on remote repositories in order to inform the developer about inappropriate technology usage (dependency enforcement). Based on a flag the build would either fail or print a warning.


Technology management benefits and means

The capability to manage dependencies and technologies on a mature level is essential for software organizations of a certain size. Technology management becomes a key discipline and must be introduced in a careful way to allow for mutual benefits among its stakeholder including developer, management, and customers.

Artifact lifecycle management

To perform effective technology management, you should keep the number of approved artifacts as small as possible. You cannot remove artifacts from the repository if you want to sustain reproducible builds. Therefore, each artifact in the repository should be marked with a corresponding lifecycle state.

The proposed main states are (but the plugin is not limited, you can create your own)

  • approved
  • prohibited
  • investigating

With these states, it solve elegantly the following use cases.

Scenario 1: Flawed versions
It turns out that my-app-1.4.2.jar contains a serious security issue and is therefore flawed. Clients of this JAR should actually switch to a newer version my-app-1.4.3.jar which fixes the bug and which is safe to use.

Scenario 2: Decommissioning
Let's assume that my-app-1.4.2.jar is not supported anymore and projects should actually switch to a new release stream
(my-app-2.x.y.jar).

Scenario 3: Restricted usage
Consider a library which has a restricted set of client projects, e.g. only certain projects are allowed to depend on a specific artifact.

Usage

Artifact lifecycle metadata must be placed in a file named maven-artifact-lifecycle.xml in the corresponding group directory. For instance, if you want to define lifecycle information for struts, the corresponding metadata file is located here: struts/struts/maven-artifact-lifecycle.xml

This plugin can be downloaded at http://madp.sourceforge.net/index.html

Donations

Thank You for supporting my work