Skip to main content
Jump to: navigation, search

M2E/Extension Development


Some OSGi bundle development and PDE knowledge is assumed. TODO link to some PDE documentation and tutorials

Java code generation overview

Although there are no strict rules, usually maven java code generation plugins like antlr3-maven-plugin or maven-jaxb-plugin take one or more input files from project source tree and generate a number java source files in a subdirectory of target/generated-sources/ directory. These generated sources are usually required to compile and/or run project tests.

To properly support code generation inside Eclipse IDE workspace, the IDE generally needs to perform some configuration (semi) statically during project import and then do actually code generation either on request or automatically as part of workspace build.

m2e extension that provides support for generation will typically need to

  • implement a subclass of org.eclipse.m2e.jdt.AbstractJavaProjectConfigurator to perform necessary project configuration
  • implement subclass of MojoExecutionBuildParticipant to delegate actual code generation to underlying maven plugin goal
  • provide metadata to metadata to register the project configurator with m2e and to map maven plugin execution to the project configurator

m2e/antlr3 code generation support explained

As an example, here is explanation of how different parts of [m2e/antlr] fit together

On command line, [antlr3-maven-plugin], reads ANTLR grammar files from directory specified by ${sourceDirectory} plugin configuration parameter (defaults to src/main/antlr3) and generates output files in directory specified by ${outputDirectory} plugin configuration parameter (defaults to target/generated-sources/antlr3).

AntlrProjectConfigurator and corresponding metadata

[AbstractJavaProjectConfigurator] is a convenience abstract implementation of AbstractProjectConfigurator that provides default behaviour common to many java code generation m2e extensions. AbstractJavaProjectConfigurator assumes single additional java source folder needs to be configured for the project and the source folder location is defined by ${outputDirectory} maven plugin configuration parameter. This allows very simple ANTLR project configurator implementation (is explained below)

   public class AntlrProjectConfigurator
       extends AbstractJavaProjectConfigurator
       public AbstractBuildParticipant getBuildParticipant( IMavenProjectFacade projectFacade,
                                                            MojoExecution execution,
                                                            IPluginExecutionMetadata executionMetadata )
           return new AntlrBuildParticipant( execution );

The follow extension in plugin.xml registers ANTLR project configurator with m2e

           name="ANTLR Project Configurator">

Project directory structure overview

 org.somecatchyname/                   <= project basedir, all project files are under this directory
   org.somecatchyname.m2e/             <= main bundle project
   org.somecatchyname.m2e.tests/       <= automated tests (optional, but highly recommended)
   org.somecatchyname.m2e.feature/     <= eclipse feature project
   pom.xml                             <= aggregator pom.xml

Submitting M2E marketplace entries

M2E extension development environment

Back to the top