Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2012-01-03 12:57:34 +0000
committerIgor Fedorenko2012-01-30 14:56:06 +0000
commit223a1d92282b26197eee466f54e4c8c253df383f (patch)
treed0ff8a5cb71863a8b102709642d221bd2f795e41 /org.eclipse.m2e.core
parent0a41027c0f88a7f11d03fe0bdf47ac057b85fa2c (diff)
downloadm2e-core-223a1d92282b26197eee466f54e4c8c253df383f.tar.gz
m2e-core-223a1d92282b26197eee466f54e4c8c253df383f.tar.xz
m2e-core-223a1d92282b26197eee466f54e4c8c253df383f.zip
359340 : Add API for Eclipse project -> Maven Model conversion
Signed-off-by: Fred Bricon <fbricon@gmail.com>
Diffstat (limited to 'org.eclipse.m2e.core')
-rw-r--r--org.eclipse.m2e.core/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.m2e.core/plugin.properties1
-rw-r--r--org.eclipse.m2e.core/plugin.xml1
-rw-r--r--org.eclipse.m2e.core/schema/projectConversionParticipants.exsd130
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java6
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java15
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java111
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/AbstractProjectConversionParticipant.java65
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionManager.java43
9 files changed, 373 insertions, 0 deletions
diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
index f1ee8591..b259c881 100644
--- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
@@ -41,6 +41,7 @@ Export-Package: org.eclipse.m2e.core,
org.eclipse.m2e.core.lifecyclemapping.model,
org.eclipse.m2e.core.project,
org.eclipse.m2e.core.project.configurator,
+ org.eclipse.m2e.core.project.conversion,
org.eclipse.m2e.core.repository
MavenArtifact-GroupId: org.eclipse.m2e
MavenArtifact-ArtifactId: org.eclipse.m2e.core
diff --git a/org.eclipse.m2e.core/plugin.properties b/org.eclipse.m2e.core/plugin.properties
index 871699c8..eb2ba31e 100644
--- a/org.eclipse.m2e.core/plugin.properties
+++ b/org.eclipse.m2e.core/plugin.properties
@@ -38,3 +38,4 @@ extension-point.mappingdefault.name = Default Maven Lifecycle Mappings
extension-point.component.name = Maven Core Component Contributor
extension-point.changed.name = mavenProjectChangedListeners
extension-point.lifecycleMappingMetadataSource.name = Lifecycle Mapping Metadata Source
+extension-point.projectConversionParticipants.name= Project conversion participants \ No newline at end of file
diff --git a/org.eclipse.m2e.core/plugin.xml b/org.eclipse.m2e.core/plugin.xml
index 0492809a..cd08c47d 100644
--- a/org.eclipse.m2e.core/plugin.xml
+++ b/org.eclipse.m2e.core/plugin.xml
@@ -16,6 +16,7 @@
<extension-point id="mavenProjectChangedListeners" name="%extension-point.changed.name" schema="schema/mavenProjectChangedListeners.exsd"/>
<extension-point id="lifecycleMappingMetadataSource" name="%extension-point.lifecycleMappingMetadataSource.name" schema="schema/lifecycleMappingMetadataSource.exsd"/>
<extension-point id="artifactFilters" name="%extension-point.artifactFilters-name" schema="schema/artifactFilters.exsd"/>
+ <extension-point id="projectConversionParticipants" name="%extension-point.projectConversionParticipants.name" schema="schema/projectConversionParticipants.exsd"/>
<extension point="org.eclipse.core.runtime.contentTypes">
<content-type id="pomFile" name="%content-type.name"
diff --git a/org.eclipse.m2e.core/schema/projectConversionParticipants.exsd b/org.eclipse.m2e.core/schema/projectConversionParticipants.exsd
new file mode 100644
index 00000000..fb219cea
--- /dev/null
+++ b/org.eclipse.m2e.core/schema/projectConversionParticipants.exsd
@@ -0,0 +1,130 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<schema targetNamespace="org.eclipse.m2e.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.m2e.core" id="projectConversionParticipants" name="org.eclipse.m2e.core.project.conversionParticipants"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="projectConversionParticipant"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="projectConversionParticipant">
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Unique project conversion participant Id
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.m2e.core.project.conversion.AbstractProjectConversionParticipant:"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ Translatable name of this conversion participant. Ex. &quot;JDT project converter&quot;
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 1.1
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2012 Red Hat, Inc.
+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
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
index 907c29b7..3be53e36 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
@@ -17,8 +17,10 @@ import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.index.IndexManager;
+import org.eclipse.m2e.core.internal.project.conversion.ProjectConversionManager;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
+import org.eclipse.m2e.core.project.conversion.IProjectConversionManager;
import org.eclipse.m2e.core.repository.IRepositoryRegistry;
@@ -69,4 +71,8 @@ public final class MavenPlugin {
return MavenPluginActivator.getDefault().getMavenModelManager();
}
+ public static IProjectConversionManager getProjectConversionManager() {
+ return MavenPluginActivator.getDefault().getProjectConversionManager();
+ }
+
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
index 87593448..13433db2 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
@@ -71,12 +71,14 @@ import org.eclipse.m2e.core.internal.markers.MavenMarkerManager;
import org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl;
import org.eclipse.m2e.core.internal.project.ProjectConfigurationManager;
import org.eclipse.m2e.core.internal.project.WorkspaceStateWriter;
+import org.eclipse.m2e.core.internal.project.conversion.ProjectConversionManager;
import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager;
import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager;
import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob;
import org.eclipse.m2e.core.internal.repository.RepositoryRegistry;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.MavenUpdateRequest;
+import org.eclipse.m2e.core.project.conversion.IProjectConversionManager;
import org.eclipse.m2e.core.repository.IRepositoryRegistry;
@@ -133,6 +135,8 @@ public class MavenPluginActivator extends Plugin {
private MavenImpl maven;
+ private IProjectConversionManager projectConversionManager;
+
public MavenPluginActivator() {
plugin = this;
@@ -239,6 +243,8 @@ public class MavenPluginActivator extends Plugin {
// fork repository registry update. must after index manager registered as a listener
this.repositoryRegistry.updateRegistry();
+
+ this.projectConversionManager = new ProjectConversionManager();
}
private static ArchetypeManager newArchetypeManager(File stateLocationDir) {
@@ -287,6 +293,8 @@ public class MavenPluginActivator extends Plugin {
this.configurationManager = null;
LifecycleMappingFactory.setBundleMetadataSources(null);
+ this.projectConversionManager = null;
+
plugin = null;
}
@@ -431,4 +439,11 @@ public class MavenPluginActivator extends Plugin {
public ArtifactFilterManager getArifactFilterManager() {
return artifactFilterManager;
}
+
+ /**
+ * @return
+ */
+ public IProjectConversionManager getProjectConversionManager() {
+ return projectConversionManager;
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java
new file mode 100644
index 00000000..4aca4e07
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.core.internal.project.conversion;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+
+import org.apache.maven.model.Model;
+
+import org.eclipse.m2e.core.project.conversion.AbstractProjectConversionParticipant;
+import org.eclipse.m2e.core.project.conversion.IProjectConversionManager;
+
+/**
+ * Manages conversion of existing Eclipse projects into Maven ones. <br/>
+ * Looks up for {@link AbstractProjectConversionParticipant} contributed by 3rd party eclipse plugins.
+ *
+ * @author Fred Bricon
+ */
+public class ProjectConversionManager implements IProjectConversionManager {
+
+ private static final String CONVERSION_PARTICIPANTS_EXTENSION_POINT = "org.eclipse.m2e.core.projectConversionParticipants";
+
+ private static final Logger log = LoggerFactory.getLogger(ProjectConversionManager.class);
+
+ private List<AbstractProjectConversionParticipant> allParticipants;
+
+ public List<AbstractProjectConversionParticipant> getAllConversionParticipants() {
+ if (allParticipants == null) {
+ allParticipants = lookupConversionParticipants();
+ }
+ return Collections.unmodifiableList(allParticipants);
+ }
+
+ private static List<AbstractProjectConversionParticipant> lookupConversionParticipants() {
+
+ List<AbstractProjectConversionParticipant> participants = new ArrayList<AbstractProjectConversionParticipant>();
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint conversionExtensionPoint = registry.getExtensionPoint(CONVERSION_PARTICIPANTS_EXTENSION_POINT);
+ if(conversionExtensionPoint != null) {
+ IExtension[] archetypesExtensions = conversionExtensionPoint.getExtensions();
+ for(IExtension extension : archetypesExtensions) {
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ for(IConfigurationElement element : elements) {
+ AbstractProjectConversionParticipant participant = readProjectConversionParticipant(element);
+ if (participant != null) {
+ participants.add(participant);
+ }
+ }
+ }
+ }
+ return Collections.unmodifiableList(participants);
+ }
+
+ private static AbstractProjectConversionParticipant readProjectConversionParticipant(IConfigurationElement element) {
+ AbstractProjectConversionParticipant participant = null;
+ try {
+ participant = (AbstractProjectConversionParticipant) element.createExecutableExtension("class");
+ } catch(CoreException ex) {
+ log.error("Can not load IProjectConversionParticipant", ex);
+ }
+ return participant;
+ }
+
+ public void convert(IProject project, Model model, IProgressMonitor monitor) throws CoreException {
+ if (model == null) {
+ return;
+ }
+ List<AbstractProjectConversionParticipant> participants = getConversionParticipants(project);
+ if (participants != null) {
+ for (AbstractProjectConversionParticipant participant : participants) {
+ participant.convert(project, model, monitor);
+ }
+ }
+ }
+
+ public List<AbstractProjectConversionParticipant> getConversionParticipants(IProject project) throws CoreException {
+ List<AbstractProjectConversionParticipant> allParticipants = getAllConversionParticipants();
+ List<AbstractProjectConversionParticipant> participants = new ArrayList<AbstractProjectConversionParticipant>();
+ if (allParticipants != null) {
+ for (AbstractProjectConversionParticipant participant : allParticipants) {
+ if (participant.accept(project)) {
+ participants.add(participant);
+ }
+ }
+ }
+ return participants;
+ }
+
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/AbstractProjectConversionParticipant.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/AbstractProjectConversionParticipant.java
new file mode 100644
index 00000000..64553a9b
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/AbstractProjectConversionParticipant.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.core.project.conversion;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.apache.maven.model.Model;
+
+/**
+ * Used to convert existing Eclipse project configuration to the corresponding Maven Model.
+ *
+ * @author Fred Bricon
+ */
+public abstract class AbstractProjectConversionParticipant implements IExecutableExtension {
+
+ public static final String ATTR_ID = "id"; //$NON-NLS-1$
+
+ public static final String ATTR_NAME = "name"; //$NON-NLS-1$
+
+ private String name;
+ private String id;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ if (id == null) {
+ id = getClass().getName();
+ }
+ return id;
+ }
+
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) {
+ this.id = config.getAttribute(ATTR_ID);
+ this.name = config.getAttribute(ATTR_NAME);
+ }
+
+ /**
+ * Checks if this participant can change the Maven Model from this Eclipse project configuration
+ */
+ public abstract boolean accept(IProject project) throws CoreException;
+
+ /**
+ * Converts existing Eclipse project configuration to Maven model
+ */
+ public abstract void convert(IProject project, Model model, IProgressMonitor monitor) throws CoreException;
+
+
+ public String toString() {
+ return (name == null)?getId():name;
+ }
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionManager.java
new file mode 100644
index 00000000..ca48e5cc
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionManager.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2e.core.project.conversion;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.apache.maven.model.Model;
+
+/**
+ * Manages conversion of existing Eclipse projects into Maven ones.
+ *
+ * @author Fred Bricon
+ */
+public interface IProjectConversionManager {
+
+ /**
+ * Converts an existing Eclipse project configuration to its Maven Model counterpart
+ */
+ void convert(IProject project, Model model, IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * Returns an unmodifiable list of all known {@link AbstractProjectConversionParticipant}s
+ */
+ List<AbstractProjectConversionParticipant> getAllConversionParticipants();
+
+ /**
+ * Returns an unmodifiable list of all {@link AbstractProjectConversionParticipant}s applying to this project
+ */
+ List<AbstractProjectConversionParticipant> getConversionParticipants(IProject project) throws CoreException;
+
+}

Back to the top