Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 297143 - New Plug-in Project should not generate an "Activator" as default option
Summary: New Plug-in Project should not generate an "Activator" as default option
Status: VERIFIED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows NT
: P3 normal with 1 vote (vote)
Target Milestone: 4.6 M7   Edit
Assignee: Lars Vogel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 297406 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-12-07 19:18 EST by Lars Vogel CLA
Modified: 2017-06-28 07:20 EDT (History)
17 users (show)

See Also:


Attachments
Screenshot showing default (68.41 KB, image/png)
2016-03-15 05:52 EDT, Alex Blewitt CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2009-12-07 19:18:24 EST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5
Build Identifier: 

Hi,

this is a follow up on the following post: http://neilbartlett.name/blog/2009/11/30/osgi-its-time-to-ban-bundle-activators/

According to this discussion Activator should be avoided. I suggest therefore that PDE should not create a Activator as default in a new plugin project. 

Best regards, Lars



Reproducible: Always

Steps to Reproduce:
Create a new plugin project-> "Generated an activator, a Java class that controls the plug-in's life cycle" is flagged as default.
Comment 1 Lars Vogel CLA 2009-12-10 12:42:11 EST
*** Bug 297406 has been marked as a duplicate of this bug. ***
Comment 2 Curtis Windatt CLA 2010-01-22 11:16:08 EST
I don't want to let this bug be completely forgotten, but it is low priority so I don't expect any of the committers will be looking at this.
Comment 3 Lars Vogel CLA 2012-07-19 13:39:07 EDT
@Curis: Would you apply a patch if I provide one to change the default flag?
Comment 4 Curtis Windatt CLA 2012-07-19 17:45:18 EDT
Most of the Eclipse plug-ins are still using them and the blog referenced in this bug has been taken down.

cc'ing Tom.  Is the use of bundle activators actively discouraged?
Comment 5 Lars Vogel CLA 2012-07-19 17:49:48 EDT
@Curtis: Theses day I wouldn't say actively discourage but I think the default should switch. AFAIK the Activator is rarely used. I might be wrong here.
Comment 6 Bryan Hunt CLA 2012-07-19 18:01:54 EDT
+1  I develop lots of bundles, and it's rare that I want an activator.
Comment 7 Prashant Deva CLA 2012-07-19 18:06:05 EDT
This is in reference to Lars Vogel's tweet:
https://twitter.com/vogella/status/226071553262096385

We do use Activator, since it seems to be mentioned in every eclipse plugin tutorial i have come across.

There is nothing on this bug which indicates why we should abandon it and what are the alternatives.
The blog post linked in the first comment gives a 404.
Comment 8 Lars Vogel CLA 2012-07-19 18:09:18 EDT
@Prashant it is not bad creating it, it is just an unused class in most cases for me. And I almost never use it.
Comment 9 Prashant Deva CLA 2012-07-19 18:12:07 EDT
(In reply to comment #8)
> @Prashant it is not bad creating it, it is just an unused class in most cases
> for me. And I almost never use it.

@Lars it seems to have explicit start(), stop() methods. We use the 'start()' method to check for licenses. Also we override initializeImageRegistry() to initialize our image registry.

There needs to be some code showing how to do this alternatively without creating an Activator class.
Comment 10 Prashant Deva CLA 2012-07-19 18:15:25 EDT
(In reply to comment #8)
> @Prashant it is not bad creating it, it is just an unused class in most cases
> for me. And I almost never use it.

Also we use it all over our code to get access to things like preference store, image registry, and some custom fields that are initialized, etc. 

It acts as a global variable container for the rest of the plugin.
Comment 11 Lars Vogel CLA 2012-07-19 18:25:01 EDT
@Prashant: It is absolutely ok to use an Activator if you have the need to. Nobody will remove this option nor deprecate the usage.

I'm just wondering if the majority of developers have the need or if your case is the exception.
Comment 12 Raphael POITTEVIN CLA 2012-07-19 21:22:21 EDT
(In reply to comment #11)
> I'm just wondering if the majority of developers have the need or if your case
> is the exception.

IMOO, the question is also : "should we encourage the use of the Activator class? In order to encourage a (as far as can be) more standard code, and some good practices."

An eclipse plugin must be as optimized and light as can be. Keeping this option on by default may be (indirectly) encouraging the use of Activators and therefore the use of 'start()' and 'initializeImageRegistry()' methods.
Comment 13 Felix Heppner CLA 2012-07-20 01:00:44 EDT
We do use Activators and I know this "central storage pattern". Nevertheless I consider singletons as a bad design idea in most cases. Change the default to not generate an Activator seems fine to me. In eclipse 4 @inject should be used rather than accessing a singleton Activator imo.
Comment 14 Vincent Zurczak CLA 2012-07-20 03:45:55 EDT
In Eclipse 3.x, I often used activators, at least for logging and for the management of image descriptors. I have not yet developped plugins for Eclipse 4 (I am still using the compatibility layer).

If it was only for Eclipse 3, I would say we should keep the option in the wizard, but let it unselected by default.
Comment 15 E Dekker CLA 2012-07-20 07:37:23 EDT
In response to tweet of Lars, I never use the Activator.
In rare cases i need to run early code i use the E4 lifecycle injection.
Our team, as policy, states that Activators are not used. We never needed to deviate from that. We only use E4. (all E3 projects are migrated)

I would vote to stop generating the Activator by default.
(and maybe allow lifecycle injection to occur using a fragment?)
Comment 16 Thomas Watson CLA 2012-07-20 08:46:04 EDT
The main reason in the past for using a BundleActivator was to inform the bundle when it has a valid bundle activator and could interact with the the OSGi service registry, obtain services, initialize the services it provides and register them etc.  In other words when the bundle is being activated.  There are now several injection containers (or extenders) that provide better models on top of the OSGi service registry that make the use of BundleActivators unnecessary.  For example, declarative services, blueprint, ipojo, e4 etc.

An issue I foresee with not making the creation of the BundleActivator the default is that PDE may soon be asked to pick a default injection container or extender to set the project up with.  Generally there are three types of bundles.

1) Pure library bundles that contain code that has no lifecycle interaction with the OSGi framework.  These bundles obviously need no bundle activator or injection container to interact with the OSGi service registry.

2) Classic OSGi bundles that interact directly with the service registry (use the BundleContext, ServiceTracker, and listeners (Bundle, Service, Framework).  Also, bundles that need to manage the lifecycle layer of the framework may fall into this type: install, start, stop, uninstall of bundles (e.g. simple configurator)

3) Bundles that use some kind of extender to interact with the service registry.

Perhaps PDE should give the developer a choice in setting up one of these three types of bundles?  Short of doing that I don't see much advantage to changing the default.
Comment 17 Paul Webster CLA 2012-07-20 10:22:32 EDT
When you also have "this plugin contributes to the UI" set, it generates an Activator based on AbstractUIPlugin (that gives access by default to image registries, image loading, bundle preferences, etc).

If you want to make "Generate an activator..." default to off would you turn "contribute to UI" off?  How do we allow them to toggle separately, but *if* "contribute to UI" is on then they most likely want access to all of the helpers provided by AbstractUIPlugin, and so "Generate an activator..." should be checked.

PW
Comment 18 Lars Vogel CLA 2012-07-23 06:41:15 EDT
I think the discussion here showed that their is no common agreement to change the default. I'm closing this bug therefore as "Won't fix".
Comment 19 Bryan Hunt CLA 2012-07-23 10:48:42 EDT
What about adding a preference that allowed you to specify the default?
Comment 20 Lars Vogel CLA 2012-07-24 04:05:23 EDT
@Brian: I think it would be nice if PDE would remember the last section by the user. Could you please open a new bug report for this?
Comment 21 Lars Vogel CLA 2015-09-23 17:30:38 EDT
Alex Blewitt is currently working relatively hard to remove Activators in platform to speed up the startup of Eclipse. I think we should reconsider the current default in PDE>
Comment 22 Alex Blewitt CLA 2015-09-23 17:31:49 EDT
I agree; it makes sense for it not to be created by default. Maybe an option on the wizard, like 'contributes to UI?', to allow it to be created, but have it deselected?
Comment 23 Lars Vogel CLA 2015-09-23 17:47:10 EDT
(In reply to Alex Blewitt from comment #22)
> I agree; it makes sense for it not to be created by default. Maybe an option
> on the wizard, like 'contributes to UI?', to allow it to be created, but
> have it deselected?

We have this option already but currently selected by default.
Comment 24 Lars Vogel CLA 2015-09-23 17:48:43 EDT
(In reply to Lars Vogel from comment #23)
> (In reply to Alex Blewitt from comment #22)
> > I agree; it makes sense for it not to be created by default. Maybe an option
> > on the wizard, like 'contributes to UI?', to allow it to be created, but
> > have it deselected?
> 
> We have this option already but currently selected by default.

I just retested, at the option "Generate an activator.." is not selected in my wizard. Not sure if this selection is persisted these days or if we changed the default in another bug.
Comment 25 Eclipse Genie CLA 2015-09-23 17:59:32 EDT
New Gerrit change created: https://git.eclipse.org/r/56577
Comment 26 Alex Blewitt CLA 2016-03-15 05:47:14 EDT
By the way, this is still an issue - a freshly downloaded copy of Eclipse against an empty workspace still has the 'Create an Activator' selected by default. Even if it remembers you turning it off, it still encourages bad behaviour by defaulting to doing the wrong thing.
Comment 27 Alex Blewitt CLA 2016-03-15 05:52:23 EDT
Created attachment 260300 [details]
Screenshot showing default
Comment 28 Lars Vogel CLA 2016-03-17 10:13:06 EDT
(In reply to Alex Blewitt from comment #27)
> Created attachment 260300 [details]
> Screenshot showing default

I don't think the default has changed yet. Maybe you want to restore and rework your Gerrit review which you started a while ago in comment 25?
Comment 29 Alex Blewitt CLA 2016-03-17 11:00:55 EDT
Restored the change and rebased. Not restested it yet.
Comment 30 Alex Blewitt CLA 2016-03-18 06:07:25 EDT
Retested commit. Still works as expected; the activator checkbox is no longer selected by default. Persistence for selected checkbox still works as expected between launches.

This is ready to merge.
Comment 31 Lars Vogel CLA 2016-03-18 06:23:19 EDT
(In reply to Alex Blewitt from comment #30)
> Retested commit. Still works as expected; the activator checkbox is no
> longer selected by default. Persistence for selected checkbox still works as
> expected between launches.
> 
> This is ready to merge.

Thanks, I test and merge this after M6 is released. Good to have you back in the code contributing camp, IMHO your contributions are highly valuable.
Comment 33 Lars Vogel CLA 2016-03-25 15:38:53 EDT
Thanks Alex.
Comment 34 Lars Vogel CLA 2016-04-24 15:36:39 EDT
Verified in 4.6.0.N20160420-2000h
Comment 35 Vikas Chandra CLA 2017-06-28 07:20:56 EDT
IMHO, this should be mentioned in N&N.