Bug 388211 - New plug-in with Graphiti editor wizard adds not needed
dependency to org.eclipse.ui

* Dependency to org.eclipse.ui is no longer added when no activator is
created
* Adapted test case
** No activator creation
** Dependency to org.eclipse.ui does not exist

Change-Id: I96914c9fc3d96d8d4f09fa713f167517cca54437
diff --git a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GraphitiEditorTemplateSection.java b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GraphitiEditorTemplateSection.java
index 16f4420..0782b96 100644
--- a/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GraphitiEditorTemplateSection.java
+++ b/plugins/org.eclipse.graphiti.tools.newprojectwizard/src/org/eclipse/graphiti/tools/newprojectwizard/internal/GraphitiEditorTemplateSection.java
@@ -9,6 +9,7 @@
  * 

  * Contributors:

  *    SAP AG - initial API, implementation and documentation

+ *    mwenz - Bug 388211 - New plug-in with Graphiti editor wizard adds not needed dependency to org.eclipse.ui

  * 

  * </copyright>

  */

@@ -30,6 +31,7 @@
 import org.eclipse.pde.core.plugin.IPluginModelFactory;

 import org.eclipse.pde.core.plugin.IPluginReference;

 import org.eclipse.pde.ui.IFieldData;

+import org.eclipse.pde.ui.IPluginFieldData;

 import org.eclipse.pde.ui.templates.OptionTemplateSection;

 import org.eclipse.pde.ui.templates.PluginReference;

 import org.eclipse.pde.ui.templates.StringOption;

@@ -62,6 +64,8 @@
 	private static final String KEY_CONNECTION_DOMAIN_OBJECT_CLASS_NAME = "connectionDomainObjectClassName"; //$NON-NLS-1$

 	private static final String KEY_CONNECTION_DOMAIN_OBJECT_CLASS_NAME_SHORT = "connectionDomainObjectClassNameShort"; //$NON-NLS-1$

 

+	private static final String KEY_GENERATE_ACTIVATOR = "generateActivator"; //$NON-NLS-1$

+

 	private SelectTypeOption shapeDomainObjectOption;

 	private SelectTypeOption connectionDomainObjectOption;

 

@@ -190,6 +194,9 @@
 	@Override

 	protected void initializeFields(IFieldData data) {

 		initializeFields(data.getId(), data.getName());

+		if (data instanceof IPluginFieldData) {

+			initializeOption(KEY_GENERATE_ACTIVATOR, ((IPluginFieldData) data).doGenerateClass());

+		}

 	}

 

 	@Override

@@ -271,6 +278,18 @@
 

 		IPluginReference[] superDependencies = super.getDependencies(schemaVersion);

 		for (IPluginReference dependency : superDependencies) {

+			if ("org.eclipse.ui".equals(dependency.getId())) { //$NON-NLS-1$

+				if (!getBooleanOption(KEY_GENERATE_ACTIVATOR)) {

+					/*

+					 * Skip dependency to og.eclipse.ui, because no activator

+					 * shall be created and we don't need this dependency for

+					 * anything else; in contrary it is harmful if one tries to

+					 * create an e4 RCP app, see

+					 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=388211

+					 */

+					continue;

+				}

+			}

 			result.add(dependency);

 		}

 

diff --git a/tests/org.eclipse.graphiti.bot.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.graphiti.bot.tests/META-INF/MANIFEST.MF
index ff901a0..2d2906a 100644
--- a/tests/org.eclipse.graphiti.bot.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.graphiti.bot.tests/META-INF/MANIFEST.MF
@@ -16,7 +16,8 @@
  org.eclipse.graphiti.examples.common;bundle-version="0.10.0",
  org.eclipse.graphiti.testtool.sketch;bundle-version="0.10.0",
  org.eclipse.graphiti.testtool.ecore;bundle-version="0.10.0",
- org.eclipse.graphiti.ui;bundle-version="0.10.0"
+ org.eclipse.graphiti.ui;bundle-version="0.10.0",
+ org.eclipse.pde.core;bundle-version="[3.7.0,4.0.0)"
 Bundle-ClassPath: .
 Bundle-Vendor: %providerName
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/PluginWizardTests.java b/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/PluginWizardTests.java
index c72342b..0d0ff94 100644
--- a/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/PluginWizardTests.java
+++ b/tests/org.eclipse.graphiti.bot.tests/src/org/eclipse/graphiti/bot/tests/PluginWizardTests.java
@@ -9,6 +9,7 @@
  *

  * Contributors:

  *    SAP AG - initial API, implementation and documentation

+ *    mwenz - Bug 388211 - New plug-in with Graphiti editor wizard adds not needed dependency to org.eclipse.ui

  *

  * </copyright>

  *

@@ -18,6 +19,9 @@
 import org.eclipse.core.resources.IProject;

 import org.eclipse.core.resources.ResourcesPlugin;

 import org.eclipse.core.runtime.NullProgressMonitor;

+import org.eclipse.pde.core.plugin.IPluginImport;

+import org.eclipse.pde.core.plugin.IPluginModelBase;

+import org.eclipse.pde.core.plugin.PluginRegistry;

 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;

 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;

 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;

@@ -68,6 +72,9 @@
 		// Provide name for new plugin project

 		bot.textWithLabel("Project name:").setText("org.eclipse.graphiti.test1");

 		bot.button("Next >").click();

+

+		// Deselect activator generation, test for Bug 388211

+		bot.checkBoxInGroup("Options", 0).deselect();

 		bot.button("Next >").click();

 

 		// Select Graphiti extension

@@ -81,7 +88,7 @@
 		// Finish the wizard

 		bot.button("Finish").click();

 

-		// Conform perspective switch

+		// Confirm perspective switch

 		shell = bot.shell("Open Associated Perspective?");

 		shell.activate();

 		bot.button("Yes").click();

@@ -95,5 +102,15 @@
 		SWTBotTree tree = view.bot().tree();

 		SWTBotTreeItem[] allItems = tree.getAllItems();

 		assertTrue(allItems.length == 0);

+

+		// Check that org.eclipse.ui is not part of the dependencies (no

+		// activator is generated), test for Bug 388211

+		IPluginModelBase newPluginModel = PluginRegistry.findModel(newProject);

+		IPluginImport[] imports = newPluginModel.getPluginBase().getImports();

+		for (IPluginImport pluginImport : imports) {

+			if ("org.eclipse.ui".equals(pluginImport.getId())) {

+				fail("'org.eclipse.ui' should not be part of the dependencies");

+			}

+		}

 	}

 }