After playing around with continuum I am back on my luntbuild feet. I really tried continuum, good community by the way, but the maven site integration is not really possible. That is at least a little bit strange. The same is valid for labelling builds. Why this introduction for a luntbuild maven story, well, with luntbuild it is possible. Maybe not perfect but possible.

Let me explain, luntbuild does have maven 2 integration, I wanted to be able to copy the results of the site target to the luntbuild artifacts directory. This is not possible out of the box. But with a small experiment I created a maven mojo that does the trick. First disadvantage, you need to provide an extra part to the pom that is only needed for copying the site. I do want to do some more research whether this was really necessary, but for now it works.

So what is in this blog item? I will give you some details on creating a plugin for maven. Then Ill present you with the configuration of luntbuild to pass parameters to maven by using environment variables. In the end just a screenshot with the artifacts of the different maven projects.

Creating the maven plugin, or mojo

There is a guide available on the maven website. Read this first, then come back for the step by step approach.

Use the appropriate archetype to create the project with maven:

mvn archetype:create 
       -DgroupId=nl.gridshore.maven.plugin 
       -DartifactId=maven-copy-site-plugin 
       -DarchetypeArtifactId=maven-archetype-mojo

Compile the project, create the eclipse project space and start up eclipse

mvn package eclipse:eclipse

An example for a plugin is allready available in the generated project. We will create our own by subclassing the AbstractPlugin class. I do not want to teach java specifics in this blog item. Therefore just the code:

package nl.gridshore.maven.plugin;

import java.io.File;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

/**
 * @author Jettro.Coenradie
 * 
 * @goal copydirectory
 * 
 * @description Copies the provided directory to the other provided directory 
 */
public class CopyFolderMojo extends AbstractMojo {

    /**
     * Location of the directory to copy from.
     * @parameter expression="${project.build.directory}"
     * @required
     */
    private File inputDirectory;
	
    /**
     * Location of the directory to copy to.
     * @parameter expression=""
     * @required
     */
    private File outputDirectory;
    
    /**
     * Name of the current project
     * @parameter expression="${project.name}"
     * @required
     */
    private String projectName;
    
    public void execute() throws MojoExecutionException, MojoFailureException {
	getLog().info("Input directory : "+inputDirectory.toString()+"\\site");
	getLog().info("Output directory : "+outputDirectory.toString());
	File in = new File(inputDirectory,"site");
	if (!in.exists()) {
		getLog().info("No site available to be copied");
		return;
	}
	File out = new File(outputDirectory,projectName);
	if (!out.exists()) {
		out.mkdirs();
	}
	in.renameTo(new File(out,in.getName()));
    }
}

If you have read the guide I mentioned, you now the javadoc attributes are important. These are used to set the parameter values and the name of the goal that is created.

Having done that, we can package and install the new goal and test it.

mvn nl.gridshore.maven.plugin:maven-copy-site-plugin:1.0-SNAPSHOT:copydirectory

You probalby get an error message, that is because you are missing a part in the pom. You need to define the outputDirectory for the move goal.

	<build>
		<plugins>
		  	<plugin>
			  <groupId>nl.gridshore.maven.plugin</groupId>
			  <artifactId>maven-copy-site-plugin</artifactId>
			  <configuration>
			    <outputDirectory>temp</outputDirectory>
			  </configuration>
			</plugin>            
  		</plugins>
	</build>

Running the command again should result into the following:

[INFO] ----------------------------------------------------------------------------
[INFO] [copy-site:copydirectory]
[INFO] Input directory : D:\sources\java\mavenplugincopysite\copy-site\target\site
[INFO] Output directory : D:\sources\java\mavenplugincopysite\copy-site\temp
[INFO] No site available to be copied
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL

Actually that is all there is to it. In order to shorten the amount of typing needed on the command line, you will need to add your plugin’s group ID to the list of group IDs searched by default. To do this, you need to add the following to your settings.xml file:

<pluginGroups>
  <pluginGroup>nl.gridshore.maven.plugin</pluginGroup>
</pluginGroups>

Now you can run the following command and the result should be the same.

mvn copy-site:copydirectory

Integrating maven 2 with luntbuild

There a re two important screens in luntbuild with respect to maven:

luntbuildmaven2_1

luntbuildmaven2_2

Finally you have to prepare you pom(s):

    ....
	<version>${buildVersion}</version>
    ....
    <plugin>
        <groupId>nl.gridshore.maven.plugin</groupId>
        <artifactId>maven-copy-site-plugin</artifactId>
        <configuration>
            <outputDirectory>${artifactsDir}</outputDirectory>
        </configuration>
    </plugin>            

If you are having problems, the sample is available at:
http://svn.javaforge.com/svn/Equinox_Student_Registration_Sample/trunk/registrations

Beware that browsing source code from the javaforge website does not work very well, it does not refresh.

Hope this helps, please drop me a comment if it does help or if you are heving problems.

Luntbuild and Maven 2, the ideal couple?