Tiny new plugin that adds OT/J support to m2e (maven).
diff --git a/plugins/org.eclipse.objectteams.mvn/.classpath b/plugins/org.eclipse.objectteams.mvn/.classpath
new file mode 100644
index 0000000..c24f8de
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="OTRE"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.objectteams.mvn/.project b/plugins/org.eclipse.objectteams.mvn/.project
new file mode 100644
index 0000000..f2cda9e
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/.project
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.eclipse.objectteams.mvn</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.objectteams.otdt.builder.OTJBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.objectteams.otdt.OTJavaNature</nature>
+	</natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.objectteams.mvn/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.objectteams.mvn/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..26934ea
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,9 @@
+#Sun Jun 12 20:08:57 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.objectteams.otdt.compiler.option.pure_java=enabled
diff --git a/plugins/org.eclipse.objectteams.mvn/META-INF/MANIFEST.MF b/plugins/org.eclipse.objectteams.mvn/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..776688d
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/META-INF/MANIFEST.MF
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %bundleName
+Bundle-SymbolicName: org.eclipse.objectteams.mvn;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Localization: plugin
+Bundle-Vendor: %bundleVendor
+Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.m2e.core;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.m2e.jdt;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.m2e.lifecyclemapping.defaults;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.m2e.maven.runtime;bundle-version="[1.0.0,1.1.0)",
+ org.eclipse.objectteams.otequinox;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.objectteams.otdt;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.jdt.core;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.core.resources;bundle-version="[3.7.100,4.0.0)"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.eclipse.objectteams.mvn/about.html b/plugins/org.eclipse.objectteams.mvn/about.html
new file mode 100644
index 0000000..20d3e88
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+ 
+<p>June 13, 2011</p>	
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;).  Unless otherwise 
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;).  A copy of the EPL is available 
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is 
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content.  Check the Redistributor's license that was 
+provided with the Content.  If no such license exists, contact the Redistributor.  Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.mvn/about.ini b/plugins/org.eclipse.objectteams.mvn/about.ini
new file mode 100644
index 0000000..367169c
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/about.ini
@@ -0,0 +1,12 @@
+aboutText=Maven Integration for Object Teams (Early Access)\n\
+\n\
+Copyright (c) 2011 GK Software AG and others.\n\
+Author: Stephan Herrmann\n\
+\n\
+This is an early access version of a connector\n\
+integrating the OTDT with m2e Maven support. \n\
+\n\
+The implementation uses OT/Equinox[1] for integration with m2e.\n\
+\n\
+[1]http://wiki.eclipse.org/Category:OTEquinox\n\
+
diff --git a/plugins/org.eclipse.objectteams.mvn/build.properties b/plugins/org.eclipse.objectteams.mvn/build.properties
new file mode 100644
index 0000000..dcde528
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/build.properties
@@ -0,0 +1,8 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml,\
+               plugin.properties,\
+               about.html,\
+               about.ini
diff --git a/plugins/org.eclipse.objectteams.mvn/plugin.properties b/plugins/org.eclipse.objectteams.mvn/plugin.properties
new file mode 100644
index 0000000..9ebf285
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/plugin.properties
@@ -0,0 +1,2 @@
+bundleName=Maven Integration for Object Teams (Early Access)
+bundleVendor=Eclipse.org - Object Teams
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.mvn/plugin.xml b/plugins/org.eclipse.objectteams.mvn/plugin.xml
new file mode 100644
index 0000000..4152fdc
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/plugin.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension
+         point="org.eclipse.objectteams.otequinox.aspectBindings">
+      <aspectBinding
+            icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/calloutbinding_obj.gif">
+         <basePlugin
+               icon="platform:/plugin/org.eclipse.pde.ui/icons/obj16/plugin_obj.gif"
+               id="org.eclipse.m2e.core">
+         </basePlugin>
+         <team
+               activation="ALL_THREADS"
+               class="org.eclipse.objectteams.mvn.internal.LifeCycleMapping"
+               icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
+         </team>
+         <team
+               class="org.eclipse.objectteams.mvn.internal.LifeCycleMapping.Context"
+               icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
+         </team>
+      </aspectBinding>
+      <aspectBinding
+            icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/calloutbinding_obj.gif">
+         <basePlugin
+               icon="platform:/plugin/org.eclipse.pde.ui/icons/obj16/plugin_obj.gif"
+               id="org.eclipse.m2e.jdt">
+         </basePlugin>
+         <team
+               activation="ALL_THREADS"
+               class="org.eclipse.objectteams.mvn.internal.Configurator"
+               icon="platform:/plugin/org.eclipse.objectteams.otdt.ui/icons/ot/team_obj.gif">
+         </team>
+      </aspectBinding>
+   </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.objectteams.mvn/src/org/eclipse/objectteams/mvn/internal/Configurator.java b/plugins/org.eclipse.objectteams.mvn/src/org/eclipse/objectteams/mvn/internal/Configurator.java
new file mode 100644
index 0000000..acc44d9
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/src/org/eclipse/objectteams/mvn/internal/Configurator.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GK Software AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Stephan Herrmann - initial API and implementation 
+ *******************************************************************************/
+package org.eclipse.objectteams.mvn.internal;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
+import org.eclipse.objectteams.otdt.core.ext.OTDTPlugin;
+import org.eclipse.objectteams.otdt.core.ext.OTJavaNature;
+
+import base org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator;
+
+/**
+ * When configuring a Java project from its maven pom, check if it's an OT/J project,
+ * which we detect by seeing a <code><flavor>otj</flavor></code> element in the
+ * compiler configuration. When an OT/J project is detected add the OTJavaNature
+ * and update builders accordingly.
+ * 
+ * @author stephan
+ */
+@SuppressWarnings("restriction")
+public team class Configurator {
+	
+	final static String MAVEN_COMPILER_PLUGIN 	= "org.apache.maven.plugins:maven-compiler-plugin";
+	final static String FLAVOR 					= "flavor";
+	final static String OTJ 					= "otj";
+
+	protected class OTJProjectConfigurator playedBy AbstractJavaProjectConfigurator {
+
+		// Fetch the request to be used by subsequent callins:
+		ProjectConfigurationRequest request;
+		storeRequest <- before configure;
+		void storeRequest(ProjectConfigurationRequest request) {
+			this.request = request;
+		}
+		
+		boolean isOTJProject(IProject project) {
+			MavenProject mavenProject = this.request.getMavenProject();
+			Plugin plugin = mavenProject.getPlugin(MAVEN_COMPILER_PLUGIN);
+			
+			if (plugin != null) {
+				Object configuration = plugin.getConfiguration();
+				if (configuration instanceof Xpp3Dom) {
+					Xpp3Dom flavor = ((Xpp3Dom) configuration).getChild(FLAVOR);
+					if (flavor != null && OTJ.equals(flavor.getValue()))
+						return true;
+				}
+			}
+			return false;
+		}
+		
+		void addOTNatureAndBuilder(IProject project) <- after void addJavaNature(IProject project, IProgressMonitor monitor)
+			when ( isOTJProject(project) && !OTJavaNature.hasOTJavaNature(project) );
+
+		// from org.eclipse.objectteams.otdt.internal.pde.ui.OTPluginProject,
+		// consider making API:
+		void addOTNatureAndBuilder(IProject project)
+				throws CoreException 
+		{
+			IProjectDescription prjDesc = project.getDescription();
+			prjDesc.setNatureIds(OTDTPlugin.createProjectNatures(prjDesc));
+			ICommand[] buildSpecs = prjDesc.getBuildSpec();
+			prjDesc.setBuildSpec(replaceOrAddOTBuilder(prjDesc, buildSpecs));
+			project.setDescription(prjDesc, null);
+		}
+
+		private static ICommand[] replaceOrAddOTBuilder(
+				IProjectDescription prjDesc, ICommand[] buildSpecs) 
+		{
+			ICommand otBuildCmd = OTDTPlugin.createProjectBuildCommand(prjDesc);
+			// replace existing Java builder?
+			for (int i = 0; i < buildSpecs.length; i++) {
+				if (buildSpecs[i].getBuilderName().equals(JavaCore.BUILDER_ID)) {
+					buildSpecs[i] = otBuildCmd;
+					return buildSpecs;
+				}
+			}
+			// not found, add to front:
+			int len = buildSpecs.length;
+			System.arraycopy(buildSpecs, 0, buildSpecs = new ICommand[len + 1],
+					1, len);
+			buildSpecs[0] = otBuildCmd;
+			return buildSpecs;
+		}
+	}
+}
diff --git a/plugins/org.eclipse.objectteams.mvn/src/org/eclipse/objectteams/mvn/internal/LifeCycleMapping.java b/plugins/org.eclipse.objectteams.mvn/src/org/eclipse/objectteams/mvn/internal/LifeCycleMapping.java
new file mode 100644
index 0000000..1df3ae4
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.mvn/src/org/eclipse/objectteams/mvn/internal/LifeCycleMapping.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GK Software AG and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Stephan Herrmann - initial API and implementation 
+ *******************************************************************************/
+package org.eclipse.objectteams.mvn.internal;
+
+import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource;
+import org.osgi.framework.Bundle;
+
+import base org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
+import base org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionFilter;
+
+/**
+ * This class intercepts reading of org.eclipse.m2e.jdt/lifecycle-mapping-metadata.xml
+ * so that we replace <code><compilerId>javac</compilerId></code>
+ * with <code><compilerId>jdt</compilerId></code>.
+ * This seems to be the only way how we can use the jdt compiler via m2e.
+ * 
+ * @author stephan
+ */
+@SuppressWarnings("restriction")
+public team class LifeCycleMapping {
+	
+	final static String M2E_JDT_PLUGIN 	= "org.eclipse.m2e.jdt";
+	final static String COMPILER_ID 	= "compilerId";
+	final static String JDT 			= "jdt";
+
+	/** Cflow-like bracket: work only while reading metadata from org.eclipse.m2e.jdt. */
+	protected team class Factory playedBy LifecycleMappingFactory {
+
+		@SuppressWarnings("decapsulation")
+		void getMetadataSource(Bundle bundle) <- replace LifecycleMappingMetadataSource getMetadataSource(Bundle bundle)
+			base when (M2E_JDT_PLUGIN.equals(bundle.getSymbolicName()));
+
+		static callin void getMetadataSource(Bundle bundle) {
+			within (new Context())
+				base.getMetadataSource(bundle);
+		}
+	}
+	/** While reading metadata from org.eclipse.m2e.jdt replace any compilerId with "jdt". */
+	protected team class Context {
+		protected class Filter playedBy PluginExecutionFilter {
+
+			void addParameter(Object key, String value) <- replace void addParameter(Object key, String value)
+				base when (COMPILER_ID.equals(key));
+
+			callin void addParameter(Object key, String value) {
+				base.addParameter(key, JDT);
+			}			
+		}
+	}
+}