Sunday, 3 October 2010

Hudson Maven Dependency Update Trigger : First Hudson plugin with maven 3 apis

I have made the first release of the Maven Dependency Update Trigger hudson plugin.
Wiki page here : http://wiki.hudson-ci.org//x/jgfDAg
This plugin will check according to the cron expression if your SNAPSHOT dependencies has been updated and (optionnaly) check if your plugins SNAPSHOT has been updated too. And trigger a build if necessary.
This is usefull if you have project dependencies not in the same hudson instance or using an other continuous integration tool.
Note this plugin use maven 3 apis to build maven projects and check dependencies.
Hudson 1.379 is required to use this plugin.



So have fun and give me feedbacks.

Wednesday, 22 September 2010

Use maven 3 apis in a hudson plugin

Using maven 3 apis in a hudson needs to change classLoader hierarchy as hudson load some old maven artifacts in the parent classLoader.
So the solution is to use a child first classLoader.
This new classLoader has been introduced in hudson 1.378. (see HUDSON-5360).
So you can now use it to made your plugin dependencies win on hudson core classLoader.
Some steps are needed.
Configuring your hpi plugin

<plugin>
<groupid>org.jvnet.hudson.tools</groupid>
<artifactid>maven-hpi-plugin</artifactid>
<version>1.54</version>
<configuration>
<pluginFirstClassLoader>true</pluginFirstClassLoader>
</configuration>
</plugin>

So now your pluginWrapper.classLoader will be of type PluginFirstClassLoader.

// pluginId is project.artifactId from your plugin pom
PluginWrapper pluginWrapper = Hudson.getInstance().getPluginManager().getPlugin( pluginId );
PluginFirstClassLoader pluginFirstClassLoader = (PluginFirstClassLoader) pluginWrapper.classLoader;


Now everthing is ready but some other tricks are needed :-)

Create a PlexusContainer (note you must use the new "plexus-guice" bridge).
This means you need the following dependency :

<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
<version>1.4.1</version>
</dependency>

And very important you must exclude dependencies from the original plexus-container

<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>${aetherVersion}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>


To prevent this you can add an enforcer rule which will chech plexus-container-default inclusion

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<phase>validate</phase>
<id>ensure-no-plexus-container</id>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>org.codehaus.plexus:plexus-container-default</exclude>
</excludes>
<message>
ensure-no-plexus-container doesn't work anymore with maven 3 librairies. you have to add some exclusions.
</message>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>


How to create the PlexusContainer from the PluginFirstClassLoader :

private PlexusContainer getPlexusContainer(PluginFirstClassLoader pluginFirstClassLoader) throws PlexusContainerException {
DefaultContainerConfiguration conf = new DefaultContainerConfiguration();
ClassWorld world = new ClassWorld();
ClassRealm classRealm = new ClassRealm( world, "project-building", pluginFirstClassLoader );
// olamy yup hackish but it's needed for plexus-shim which needs a URLClassLoader and PluginFirstClassLoader is not
for ( URL url : pluginFirstClassLoader.getURLs() )
{
classRealm.addURL( url );
LOGGER.fine( "add url " + url.toExternalForm() );
}
conf.setRealm( classRealm );

return new DefaultPlexusContainer( conf );
}


Then set the current Thread classLoader (don't miss to restore the original one in a finally statement

PlexusContainer plexusContainer = getPlexusContainer( pluginFirstClassLoader );

Thread.currentThread().setContextClassLoader( plexusContainer.getContainerRealm() );


Now you can play with maven 3 apis

ProjectBuilder projectBuilder = plexusContainer.lookup( ProjectBuilder.class );


A first sample is the plugin called : maven-dependency-update-trigger
: sources and Wiki Page (under construction :-) )
You must have a look at the dependencies used.

The plugin will check your project according to a cron expression and schedule a build if a snapshot dependency has changed (dependency and plugin).

It will be released as son as hudson 1.378 will be released.

Note : hpi:run doesn't work yet for this plugin as it needs some changes in the hpi mojo to handle the new PluginFirstClassLoader.

Thursday, 9 September 2010

Searching new challenge

Hi,
I'm currently searching new challenge for my work life.
And why not a kind of new life.
If you don't know me : my work or my opensource life.
You will find a resume here http://people.apache.org/~olamy/resume/.
Note as I'm a opensource/maven addict it's in a maven format.
The license is very flexible.
So feel free to fork or distribute this resume :-).

--
Olivier

Maven site plugin 3.0-beta-2 for maven release

Hi,
A new version of the maven-site-plugin for maven 3 has been released.
See announce [ANN] Release Maven Site Plugin 3.0-beta-2 for maven 3.
It works only with last core beta-3.

Have Fun !
--
Olivier

Saturday, 21 November 2009

Using javamelody in your application

I have discovered today the project javamelody which collects some imformations at the jvm level and at the os level.
Installing it in your webapp is very easy.
In your pom add a dependency :

<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-core</artifactId>
<version>1.16.0</version>
</dependency>

This dependency is not in central repo so you have to add two repository in youe favorite repository manager.
* http://maven.glassfish.org/content/groups/public/
* http://repo.opennms.org/maven2

In your webapp add the following entries

<listener>
<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>

<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Hit your browser at http://ip:port/context/monitoring

The display is similar to the tool called orca but on real time.


Saturday, 3 October 2009

Livre sur maven en français

Un livre sur maven en français Annonce.
Cet ouvrage a la particularité de ne pas être un manuel mais de se baser sur des "histoires/aventures" autour de l'utilisation de maven.

Tuesday, 25 August 2009

maven 3.x and site plugin

The current site plugin won't work with mvn 3.x (current trunk) due to http://jira.codehaus.org/browse/MNG-4162.
So a new branch has been started http://svn.apache.org/repos/asf/maven/plugins/branches/maven-site-plugin-3.x/.
You must use it with mvn trunk and all is fine.
Note due to http://jira.codehaus.org/browse/MJAVADOC-251 you have to use a SNAPSHOT of the javadoc plugin.
Basic reports has been tested. I have to work/test more on more complex report (surefire cobertura).
Have fun !