Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 297406

Summary: [PDE Templates] Remove Activator
Product: [Eclipse Project] PDE Reporter: Lars Vogel <Lars.Vogel>
Component: UIAssignee: PDE-UI-Inbox <pde-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: caniszczyk, curtis.windatt.public, Lars.Vogel, njbartlett, ralf
Version: 3.5   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Lars Vogel CLA 2009-12-09 17:05:32 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,

can we remove the "Activator" class from the "Hello RCP" and "RCP application with a view" PDE template?

I don't think they are needed and according to recent discussions in the Eclipse blogger world "Activators" should be avoided.

Best regards, Lars

Reproducible: Always
Comment 1 Ralf Ebert CLA 2009-12-09 21:00:27 EST
Are DS components that well-established already?
Comment 2 Lars Vogel CLA 2009-12-10 00:40:09 EST
Hi Ralf,

you don't need DS or the Activator. You can use directly FrameworkUtil. See http://www.vogella.de/blog/2009/12/08/eclipse-rcp-proxy-preference/ for an example.

Best regards, Lars
Comment 3 Ralf Ebert CLA 2009-12-10 04:32:36 EST
Hmm, for tracking services, ok. But you may want to publish services which are coupled to the lifecycle to the bundle or just do some initialization/cleanup work when the bundle starts/stops. An activator is imo fine for this, even if it can be replaced with DS components. Thought you referred to Neil's blog post http://neilbartlett.name/blog/2009/11/30/osgi-its-time-to-ban-bundle-activators/ .

Using FrameworkUtil to resolve the bundle seems nice, inserting an example here for further reference:

new ServiceTracker(
     FrameworkUtil.getBundle(this.getClass()).getBundleContext(),
     ISomeService.class.getName(), null);

Is this best practice? Should the PDE templates do it like that?
Comment 4 Neil Bartlett CLA 2009-12-10 05:06:44 EST
(In reply to comment #3)
> Hmm, for tracking services, ok. But you may want to publish services which are
> coupled to the lifecycle to the bundle or just do some initialization/cleanup
> work when the bundle starts/stops.

A DS component is probably better than an Activator in these cases too. For service publishing certainly, because the service is published without needing to create a classloader for the bundle. Even for simple initialization and cleanup, it's an advantage to be able to write this without using the OSGi APIs. Also a DS component will have easier access to configuration and services.

But the main reason for not enabling Activator generation by default is simply that the Activator generated by PDE is useless. Most bundles do not need it, and in some cases it gets in the way, so just flip the default.

> new ServiceTracker(
>      FrameworkUtil.getBundle(this.getClass()).getBundleContext(),
>      ISomeService.class.getName(), null);
> 
> Is this best practice? Should the PDE templates do it like that?

I think this is bad practice. The Bundle.getBundleContext() method was never designed to be used as a matter of course by bundles to get their own context; it was designed to make it possible to implement extender bundles like the DS runtime or Spring-DM etc that work across different framework implementations. When a Java security manager is in force, this method may be disabled for use by "normal" bundles.
Comment 5 Lars Vogel CLA 2009-12-10 12:42:10 EST
I just realized that the templates do not need an update. The activator is not generated if the flag "Generate Activator" is not set. Marking this bug as duplicate of : https://bugs.eclipse.org/bugs/show_bug.cgi?id=297143

*** This bug has been marked as a duplicate of bug 297143 ***