Archive

Archive for August, 2011

Using SCM from within your Mojo

No Gravatar

There is a guide on the topic from Maven. But that guide is missing an example on how to use it from within Mojo.

So let me show you a short example on a topic… Read more…

Share

How to find out if the given Maven project is a root of a multi-module execution?

No Gravatar

[Update:] Looks like the originator is Brian Fox from Sonatype with this article.

A short example on how to find out if the given maven execution is the root of execution, — or in other words: how to know if you are inside of a multi-module project module or in the parent?

Just extend your Maven Mojo from this abstract mojo and call isThisTheExecutionRoot()

import java.io.File;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;

public abstract class AbstractMojo extends AbstractMojo {

	/** Maven Session.
	 *
	 * @parameter default-value="${session}"
	 * @required
	 * @readonly
	 */
	protected MavenSession mavenSession;

	/** Base working directory.
	 *
	 * @parameter default-value="${project.basedir}"
	 * @required
	 * @readonly
	 */
	protected File basedir;

	/**
	 * Returns true if the current project is located at the Execution Root
	 * Directory (where mvn was launched)
	 *
	 * @return true if execution root
	 */
	protected final boolean isThisTheExecutionRoot() {
		final boolean result = mavenSession.getExecutionRootDirectory()
				.equalsIgnoreCase(basedir.toString());
		return result;
	}
}

This code probably originates from Maven Changes Report Plugin: http://maven.apache.org/plugins/maven-changes-plugin/xref/index.html, but as I failed to find it within 10 minutes, I thought it might worth sharing.

Share