Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.m2e.core.ui/plugin.properties3
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenArtifactComponent.java8
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java30
-rw-r--r--org.eclipse.m2e.core/plugin.xml3
-rw-r--r--org.eclipse.m2e.core/schema/conversionEnabler.exsd128
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java77
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/AbstractProjectConversionEnabler.java52
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionEnabler.java52
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionManager.java10
9 files changed, 356 insertions, 7 deletions
diff --git a/org.eclipse.m2e.core.ui/plugin.properties b/org.eclipse.m2e.core.ui/plugin.properties
index da48ae02..bc485714 100644
--- a/org.eclipse.m2e.core.ui/plugin.properties
+++ b/org.eclipse.m2e.core.ui/plugin.properties
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2007, 2008 Sonatype, Inc.
+# Copyright (c) 2007, 2013 Sonatype, 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
@@ -110,6 +110,7 @@ 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.conversionEnabler.name = Project Conversion Enabler
convert.to.maven.name=Convert to Maven Project
m2.build.directory.filter.name=Maven build folder
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenArtifactComponent.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenArtifactComponent.java
index 78ee06bf..dc2566ee 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenArtifactComponent.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenArtifactComponent.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, 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
@@ -215,6 +215,12 @@ public class MavenArtifactComponent extends Composite {
versionCombo.setText(version);
}
+ public void setPackagingTypes(String[] packagingTypes) {
+ if(packagingCombo != null) {
+ packagingCombo.setItems(packagingTypes);
+ }
+ }
+
public void setPackaging(String packaging) {
if(packagingCombo != null) {
packagingCombo.setText(packaging);
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java
index 3c14363b..8ecf355b 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenPomWizardPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, 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
@@ -12,8 +12,10 @@
package org.eclipse.m2e.core.ui.internal.wizards;
import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -30,6 +32,9 @@ import org.eclipse.ui.dialogs.ContainerSelectionDialog;
import org.apache.maven.model.Model;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.project.conversion.IProjectConversionEnabler;
+import org.eclipse.m2e.core.project.conversion.IProjectConversionManager;
import org.eclipse.m2e.core.ui.internal.Messages;
@@ -43,6 +48,8 @@ public class MavenPomWizardPage extends AbstractMavenWizardPage {
private MavenArtifactComponent pomComponent;
+ private IProjectConversionEnabler projectConversionEnabler;
+
public MavenPomWizardPage(ISelection selection) {
super("wizardPage"); //$NON-NLS-1$
setTitle(Messages.MavenPomWizardPage_title);
@@ -89,6 +96,8 @@ public class MavenPomWizardPage extends AbstractMavenWizardPage {
* Tests if the current workbench selection is a suitable container to use.
*/
private void initialize() {
+ String packagingToUse = MavenArtifactComponent.DEFAULT_PACKAGING;
+ String[] availablePackagingTypes = MavenArtifactComponent.PACKAGING_OPTIONS;
if(selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
IStructuredSelection ssel = (IStructuredSelection) selection;
if(ssel.size() > 1) {
@@ -105,11 +114,20 @@ public class MavenPomWizardPage extends AbstractMavenWizardPage {
projectText.setText(container.getFullPath().toString());
pomComponent.setArtifactId(container.getName());
pomComponent.setGroupId(container.getName());
+ if(container instanceof IProject) {
+ IProjectConversionManager pcm = MavenPlugin.getProjectConversionManager();
+ projectConversionEnabler = pcm.getConversionEnablerForProject((IProject) container);
+ if(projectConversionEnabler != null) {
+ availablePackagingTypes = projectConversionEnabler.getPackagingTypes((IProject) container);
+ packagingToUse = availablePackagingTypes[0];
+ }
+ }
}
}
pomComponent.setVersion(MavenArtifactComponent.DEFAULT_VERSION);
- pomComponent.setPackaging(MavenArtifactComponent.DEFAULT_PACKAGING);
+ pomComponent.setPackagingTypes(availablePackagingTypes);
+ pomComponent.setPackaging(packagingToUse);
pomComponent.setFocus();
}
@@ -175,6 +193,14 @@ public class MavenPomWizardPage extends AbstractMavenWizardPage {
return;
}
+ if(container instanceof IProject && projectConversionEnabler != null) {
+ IStatus status = projectConversionEnabler.canBeConverted((IProject) container);
+ if(status.getSeverity() == IStatus.ERROR) {
+ updateStatus(status.getMessage());
+ return;
+ }
+ }
+
// TODO
if(pomComponent.getGroupId().length() == 0) {
updateStatus(Messages.MavenPomWizardPage_error_grid);
diff --git a/org.eclipse.m2e.core/plugin.xml b/org.eclipse.m2e.core/plugin.xml
index 679edb5a..a392603f 100644
--- a/org.eclipse.m2e.core/plugin.xml
+++ b/org.eclipse.m2e.core/plugin.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2007, 2008 Sonatype, Inc.
+ Copyright (c) 2007, 2013 Sonatype, 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
@@ -17,6 +17,7 @@
<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 id="conversionEnabler" name="%extension-point.conversionEnabler.name" schema="schema/conversionEnabler.exsd"/>
<extension point="org.eclipse.core.runtime.contentTypes">
<content-type id="pomFile" name="%content-type.name"
diff --git a/org.eclipse.m2e.core/schema/conversionEnabler.exsd b/org.eclipse.m2e.core/schema/conversionEnabler.exsd
new file mode 100644
index 00000000..bcf334ad
--- /dev/null
+++ b/org.eclipse.m2e.core/schema/conversionEnabler.exsd
@@ -0,0 +1,128 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.m2e.core.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.m2e.core.ui" id="conversionEnabler" name="conversionEnabler"/>
+ </appinfo>
+ <documentation>
+ This extension point can be used to test if a project should be converted to Maven or not. It can be used also to provide suggested packaging types, based on the type of project.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="enabler"/>
+ </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="enabler">
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Unique id for this project conversion enabler.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ The class that will determine if the project should should be converted or not. It must implement org.eclipse.m2e.core.project.conversion.IProjectConversionEnabler. The class org.eclipse.m2e.core.project.conversion.AbstractIProjectConversionEnabler, which implements org.eclipse.m2e.core.project.conversion.IProjectConversionEnabler, can be used by extenders.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.m2e.core.project.conversion.IProjectConversionEnabler"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="weight" type="string">
+ <annotation>
+ <documentation>
+ If not specified, the default value is 50. If there are more than one project enablers for a project, the enabler with the higher weight wins.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 1.3
+ </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 IBM Corporation 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
+ </documentation>
+ </annotation>
+
+</schema>
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
index f6321a39..f3bc8212 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Red Hat, Inc.
+ * Copyright (c) 2012-2013 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
@@ -12,9 +12,12 @@
package org.eclipse.m2e.core.internal.project.conversion;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -34,6 +37,7 @@ 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.IProjectConversionEnabler;
import org.eclipse.m2e.core.project.conversion.IProjectConversionManager;
@@ -50,6 +54,12 @@ public class ProjectConversionManager implements IProjectConversionManager {
private static final Logger log = LoggerFactory.getLogger(ProjectConversionManager.class);
+ private static final int DEFAULT_WEIGHT = 50;
+
+ private static IProjectConversionEnabler[] enablers;
+
+ private static final String CONVERSION_ENABLER_EXTENSION_POINT = "org.eclipse.m2e.core.conversionEnabler";
+
private static List<AbstractProjectConversionParticipant> lookupConversionParticipants(IProject project) {
List<AbstractProjectConversionParticipant> participants = new ArrayList<AbstractProjectConversionParticipant>();
@@ -152,4 +162,69 @@ public class ProjectConversionManager implements IProjectConversionManager {
return Collections.unmodifiableList(participants);
}
+ private static IProjectConversionEnabler[] loadProjectConversionEnablers() {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] cf = registry.getConfigurationElementsFor(CONVERSION_ENABLER_EXTENSION_POINT);
+ List<IConfigurationElement> list = Arrays.asList(cf);
+
+ Comparator<IConfigurationElement> c = new Comparator<IConfigurationElement>() {
+ public int compare(IConfigurationElement o1, IConfigurationElement o2) {
+ String o1String, o2String;
+ int o1int, o2int;
+ o1String = o1.getAttribute("weight");
+ o2String = o2.getAttribute("weight");
+ try {
+ o1int = Integer.parseInt(o1String);
+ } catch(NumberFormatException nfe) {
+ o1int = DEFAULT_WEIGHT;
+ }
+ try {
+ o2int = Integer.parseInt(o2String);
+ } catch(NumberFormatException nfe) {
+ o2int = DEFAULT_WEIGHT;
+ }
+ return o2int - o1int;
+ }
+ };
+ Collections.sort(list, c);
+ ArrayList<IProjectConversionEnabler> retList = new ArrayList<IProjectConversionEnabler>();
+ Iterator<IConfigurationElement> i = list.iterator();
+ while(i.hasNext()) {
+ try {
+ IConfigurationElement element = i.next();
+ retList.add((IProjectConversionEnabler) element.createExecutableExtension("class"));
+ if(log.isDebugEnabled()) {
+ String id = element.getAttribute("id");
+ String sWeight = element.getAttribute("weight");
+ log.debug("Project conversion enabler found - id: {}, weight: {}", id, sWeight);
+ }
+ } catch(CoreException ce) {
+ log.error(ce.getMessage(), ce);
+ }
+ }
+ return retList.toArray(new IProjectConversionEnabler[retList.size()]);
+ }
+
+ public IProjectConversionEnabler getConversionEnablerForProject(IProject project) {
+ if(enablers == null) {
+ enablers = loadProjectConversionEnablers();
+ }
+ IProjectConversionEnabler result = null;
+
+ for(IProjectConversionEnabler enabler : enablers) {
+ if(enabler.accept(project)) {
+ result = enabler;
+ break;
+ }
+ }
+ if(log.isDebugEnabled()) {
+ if(result != null)
+ log.debug("Project conversion enabler found for project: {} - Class: {} ", project.getName(), result.getClass()
+ .getName());
+ else
+ log.debug("Project conversion enabler not found for project: {}", project.getName());
+ }
+ return result;
+ }
+
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/AbstractProjectConversionEnabler.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/AbstractProjectConversionEnabler.java
new file mode 100644
index 00000000..f2d15e26
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/AbstractProjectConversionEnabler.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.project.conversion;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * AbstractProjectConversionEnabler.
+ *
+ * Convenience class that can be used by extenders of extension point org.eclipse.m2e.core.conversionEnabler
+ *
+ * @author Roberto Sanchez
+ */
+public abstract class AbstractProjectConversionEnabler implements IProjectConversionEnabler {
+
+ private static final String JAR = "jar"; //$NON-NLS-1$
+ private static final String[] PACKAGING_OPTIONS = {JAR};
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.m2e.core.project.conversion.IProjectConversionEnabler#accept(org.eclipse.core.resources.IProject)
+ */
+ public boolean accept(IProject project) {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.m2e.core.project.conversion.IProjectConversionEnabler#shouldProjectBeConverted(org.eclipse.core.resources.IProject)
+ */
+ public IStatus canBeConverted(IProject project) {
+ return Status.OK_STATUS;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.m2e.core.project.conversion.IProjectConversionEnabler#getPackagingTypes(org.eclipse.core.resources.IProject)
+ */
+ public String[] getPackagingTypes(IProject project) {
+ return PACKAGING_OPTIONS;
+ }
+
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionEnabler.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionEnabler.java
new file mode 100644
index 00000000..0af09d3d
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/conversion/IProjectConversionEnabler.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.project.conversion;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * IProjectConversionEnabler
+ *
+ * @author Roberto Sanchez
+ */
+public interface IProjectConversionEnabler {
+
+ /**
+ * Test if this enabler is interested in analyzing this project
+ *
+ * @return true if the analyzer wants to work on this project.
+ */
+ public boolean accept(IProject project);
+
+ /**
+ * Test if project should be converted to Maven. Enablers might have reasons for
+ * not allowing certain types of project to be converted to Maven
+ *
+ * @return IStatus indicating if project can be converted or not. if the project should
+ * not be converted, the severity must be set to IStatus.ERROR. If the project should be converted,
+ * the severity must be set to IStatus.OK. This method should not return null.
+ */
+ public IStatus canBeConverted(IProject project);
+
+
+ /**
+ * If project can be converted to Maven, the enabler should provide the suggested packaging types
+ * for the project.
+ *
+ * @return array of suggested packaging types. This should not return null.
+ */
+ public String[] getPackagingTypes(IProject project);
+
+
+
+}
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
index 7665e8c5..643a72d9 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Red Hat, Inc.
+ * Copyright (c) 2012-2013 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
@@ -50,4 +50,12 @@ public interface IProjectConversionManager {
*/
List<AbstractProjectConversionParticipant> getConversionParticipants(IProject project, String packaging)
throws CoreException;
+
+ /**
+ * Returns an {@link IProjectConversionEnabler} for the project, if one exists
+ *
+ * @return an {@link IProjectConversionEnabler} for the project, or null if one cannot be found.
+ */
+
+ IProjectConversionEnabler getConversionEnablerForProject(IProject project);
}

Back to the top