Bug 278845 - Separate launcher code from UI
Summary: Separate launcher code from UI
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: 3.6 M3   Edit
Assignee: Chris Aniszczyk CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on: 278844 290054
Blocks: 263547 243293
  Show dependency tree
 
Reported: 2009-06-02 14:39 EDT by Achim Demelt CLA
Modified: 2009-09-23 12:40 EDT (History)
9 users (show)

See Also:
darin.eclipse: review+
caniszczyk: review+


Attachments
Initial Patch (723.97 KB, patch)
2009-08-27 12:57 EDT, Achim Demelt CLA
no flags Details | Diff
pde-launching.psf (273 bytes, patch)
2009-09-02 15:20 EDT, Chris Aniszczyk CLA
no flags Details | Diff
Updated patch (467.75 KB, patch)
2009-09-04 05:36 EDT, Achim Demelt CLA
caniszczyk: iplog+
Details | Diff
Screenshot of the old error dialog (83.68 KB, image/png)
2009-09-04 05:39 EDT, Achim Demelt CLA
no flags Details
Screenshot of new error dialog (73.61 KB, image/png)
2009-09-04 05:40 EDT, Achim Demelt CLA
no flags Details
Updated patch (377.61 KB, patch)
2009-09-07 10:19 EDT, Achim Demelt CLA
no flags Details | Diff
(Hopefully) final patch (420.43 KB, patch)
2009-09-08 09:54 EDT, Achim Demelt CLA
caniszczyk: iplog+
Details | Diff
org.eclipse.pde.ui.patch (332.87 KB, patch)
2009-09-08 14:37 EDT, Chris Aniszczyk CLA
no flags Details | Diff
org.eclipse.pde.patch (537.99 KB, text/plain)
2009-09-21 14:31 EDT, Chris Aniszczyk CLA
no flags Details
org.eclipse.pde.ui.patch (345.87 KB, patch)
2009-09-21 14:51 EDT, Chris Aniszczyk CLA
no flags Details | Diff
patch (345.64 KB, patch)
2009-09-22 13:08 EDT, Darin Wright CLA
no flags Details | Diff
org.eclipse.pde.patch (338.54 KB, patch)
2009-09-22 13:42 EDT, Chris Aniszczyk CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Achim Demelt CLA 2009-06-02 14:39:59 EDT
Currently, the org.eclipse.pde.ui bundle contains all of PDE's launching code. This mingling with UI code prevents using the launcher in a headless environment. In particular, this blocks a decent JUnit integration with Buckminster. See this discussion in the buckminster-dev newsgroup: http://dev.eclipse.org/mhonarc/lists/buckminster-dev/msg00759.html
Comment 1 Achim Demelt CLA 2009-06-02 14:42:15 EDT
Bug #278844 is the equivalent enhancement request for JDT's JUnit integration. That must be fixed first before it makes sense to do anything in PDE.
Comment 2 Achim Demelt CLA 2009-07-22 10:05:22 EDT
Hi PDE team. I've read your plans for the 3.6 release and I'd like to raise awareness for this issue here. The fixes for Bug #278844 are basically finished and wait for approval and application to CVS. Sebastian (Zarnekow, from the Xtext team) and I are now planning to start working on this issue soon. We'd appreciate if you guys could reserve some time for reviewing our changes within the next couple of weeks. The patch will be huge because we'll have to move a number of classes. It would be best if we could do this as early in the 3.6 development cycle as possible.

Any objections from your side?
Comment 3 Chris Aniszczyk CLA 2009-07-22 10:31:20 EDT
(In reply to comment #2)
> Any objections from your side?

No, we love patches. Let us know when you're ready and we'll work with you. 

Comment 4 Guillaume CHATELET CLA 2009-07-28 08:04:14 EDT
Adding Guillaume to CC.
Comment 5 Chris Aniszczyk CLA 2009-08-13 02:01:02 EDT
Achim, are you ready to work on this given that the JDT changes will be going in soon?
Comment 6 Sebastian Zarnekow CLA 2009-08-13 02:36:59 EDT
(In reply to comment #5)
> Achim, are you ready to work on this given that the JDT changes will be going
> in soon?
> 

Hi Chris,

I've been working together with Achim on this one and we already implemented a working solution. We still want to clean up some things but I think the first patch will be available in the next days.

Regards,
Sebastian

Comment 7 Chris Aniszczyk CLA 2009-08-13 02:56:49 EDT
Please note that the patch can't break API, just be cautious of that.

Thanks for working on this.
Comment 8 Achim Demelt CLA 2009-08-13 04:18:01 EDT
Here's some more info about where we are right now:

We've been working collaboratively on a temporary Google code repository. If
you want to take a first look, checkout instructions are here:
http://code.google.com/p/pde-junit/source/checkout

Things are looking really good. I was able to include the new pde.launching
bundle in headless Buckminster and execute headless JUnit 4 plug-in tests.

We still have some clean-up work to do, like throwing out some constants and
NLS messages that we've copied over from the UI bundle. Oh, and yes, we accidentally moved a couple of API classes into other (non-UI)
packages. We'll restore them soon.

Other than that, the only annoying thing is that the PDESourceLookupDirector
has a "soft" dependency on WorkingSetSourceContainer, which comes from the
debug.ui bundle. Luckily, that's only a reference to the the container's
TYPE_ID constant. I replaced that with a String literal, and things work fine
now. Maybe you can come up with a better solution.
Comment 9 Chris Aniszczyk CLA 2009-08-13 19:42:55 EDT
Let us know when you have something concrete to review.

Thanks.
Comment 10 Achim Demelt CLA 2009-08-27 12:57:37 EDT
Created attachment 145815 [details]
Initial Patch

Sebastian and I have now finalized our work on the refactoring of the PDE launching facilities. The attached patch contains the changes to the org.eclipse.pde.ui as well as the new org.eclipse.pde.launching bundle. Here's what we did:

1) Moved the relevant classes from org.eclipse.pde.internal.ui and ...ui.launcher into org.eclipse.pde.internal.launching and ...launching.launcher, respectively.

2) Moved some classes from o.e.pde.ui.launcher to o.e.pde.launching.launcher. The UI bundle still contains the classes, but they are marked deprecated and now merely extend their o.e.pde.launching.launcher counterparts. o.e.pde.ui re-exports o.e.pde.launching. Thus, the API is fully compatible.

3) We had to make some minor changes for the separation of launching code and the UI code. This involved adding new API. Sebastian will elaborate on this, since this was his work.

4) The osgiFrameworks extension point was also moved into the o.e.pde.launching bundle. The extension point ID, however, is still o.e.pde.ui.osgiFrameworks so we have no API break here, too.

5) We split up and cleaned up declarations of constants and the NLS messages.

6) Two preference settings (PROP_AUTO_MANAGE and DEFAULT_OSGI_FRAMEOWRK) are used in the launching part. These settings are now consequently stored in the o.e.pde.launching InstanceScope. A PreferenceInitializer migrates these settings from the o.e.pde.ui scope to the new scope. Also, the PDE preference UI now stores these two values in the new scope.

NOTICE: You will have to apply Patch 6 from bug #278844 before applying this patch in order to have a compilable result. This one obviously depends on the new o.e.jdt.junit.core stuff.

When you review the code, please don't forget the issue with the PDESourceLookupDirector that I mentioned in comment #8.

We're looking forward to your comments :-)
Comment 11 Chris Aniszczyk CLA 2009-08-27 17:25:56 EDT
I will review for M2.

This patch is large enough that we need to go through the IP process.
Comment 12 Sebastian Zarnekow CLA 2009-08-31 07:45:52 EDT
(In reply to comment #10)

> 3) We had to make some minor changes for the separation of launching code and
> the UI code. This involved adding new API. Sebastian will elaborate on this,
> since this was his work.

I've identified the various places that used UI components to interact with the user even if the other aspects of the class did not have something to do with the UI.

I refactored those bits and peaces and introduced a strategy interface with a bunch of loosly related methods (handleThisErrorCondition, handleThatErrorCondition...). There are two implementations for this interface, one with UI dependencies to interact with the user, display dialogs or whatever (placed in the ui plugin), another with a reasonable default behaviour (in the rt plugin). An instance that fullfils this interface can be obtained from the rt plugin activator which is configured with a factory for this purpose. The ui plugin activator assigns another factory to be used.

This solution should not break backwards compatibility as no existing public API had to be changed.
Comment 13 Chris Aniszczyk CLA 2009-09-02 15:20:15 EDT
Created attachment 146314 [details]
pde-launching.psf

Here is a PSF file. I created org.eclipse.pde.launching bundle in the PDE incubator so we can work off of patches now. Please provide patches using this bundle now.
Comment 14 Chris Aniszczyk CLA 2009-09-02 15:36:17 EDT
Now that bug 278844 has been fixed, we can start working on this.

Here's a couple things that need to be addressed:

1) everything in the org.eclipse.pde.ui.launcher package needs to stay in it. I started some of this work but it's not done yet. We have to do this so we don't break API.

2) For error conditions, we should use the same pattern that Debug uses. That is, I'm not happy with the way HeadlessPDELauncherSettings works at the moment.

We can slowly start working on these items.
Comment 15 Achim Demelt CLA 2009-09-03 09:15:12 EDT
> 1) everything in the org.eclipse.pde.ui.launcher package needs to stay in it. I
> started some of this work but it's not done yet. We have to do this so we don't
> break API.
> 

The API tools did not complain about broken API with the solution from the initial patch. All classes from the org.eclipse.pde.ui.launcher package are still present, albeit deprecated, in the org.eclipse.pde.ui bundle. Why does the org.eclipse.pde.launching bundle have to expose the org.eclipse.pde.ui package? Sure, clients won't see so many deprecation warnings if we don't change the package name. But we don't break anything, and all a client needs to do is to change the import statements.

> 2) For error conditions, we should use the same pattern that Debug uses. That
> is, I'm not happy with the way HeadlessPDELauncherSettings works at the moment.
> 

I'll take a look at this.

> We can slowly start working on these items.

Just to be sure: We're working on the vanilla org.eclipse.pde.launching project that you've checked into CVS, and the org.eclipse.pde.ui bundle modified with its share of the initial patch that I've attached, right?
Comment 16 Chris Aniszczyk CLA 2009-09-03 12:16:34 EDT
(In reply to comment #15)
 > The API tools did not complain about broken API with the solution from the
> initial patch. All classes from the org.eclipse.pde.ui.launcher package are
> still present, albeit deprecated, in the org.eclipse.pde.ui bundle. Why does
> the org.eclipse.pde.launching bundle have to expose the org.eclipse.pde.ui
> package? Sure, clients won't see so many deprecation warnings if we don't
> change the package name. But we don't break anything, and all a client needs to
> do is to change the import statements.

I don't like the deprecated approach, I think it's cleaner if we just move the package. No API is broken either way.

> Just to be sure: We're working on the vanilla org.eclipse.pde.launching project
> that you've checked into CVS, and the org.eclipse.pde.ui bundle modified with
> its share of the initial patch that I've attached, right?

Correct, we are working off that project and the org.eclipse.pde.ui bundle in HEAD at the moment. So whatever you post as a patch, can be cleanly applied and tested.
Comment 17 Curtis Windatt CLA 2009-09-03 14:25:11 EDT
Great to see that this work is coming along.
Comment 18 Achim Demelt CLA 2009-09-04 05:36:39 EDT
Created attachment 146484 [details]
Updated patch

I've done this to get rid of the IPDELauncherSettings:

* I removed the IPDELaunchConfigurationHelper interface. Instead of delegating to the helper to display a CoreException in AbstractPDELaunchConfiguration.launch(), I simply rethrow it. This results in a slightly different error dialog in the UI, but the net result is about the same. I'll attach screenshots in a minute.

* I also removed the IPDELaunchListener interface. The LaunchListener itself is now in the org.eclipse.pde.launching bundle. It uses IStatusHandlers from the DebugPlugin to handle errors. The org.eclipse.pde.ui bundle registers handlers for these conditions. If no handlers are registered (i.e. in pure headless mode), the errors are simply logged.

Is that what you had in mind? If so, I'll continue with this strategy for the other responsibilities of the IPDELauncherSettings. I'd appreciate if you committed the changes from this patch into the pde.launching incubator. This helps me isolate upcoming changes.

Please note that I failed to come up with a situation that produces returnValue == 15, i.e. a failed launch because of a workspace in use. It seems that PDE catches this error _before_ the application is actually launched.

I've also changed the bundle version to 3.6.0. Since the API classes have benn moved into the launching bundle, bug #265699 seems to require that we must not start with 1.0.0.
Comment 19 Achim Demelt CLA 2009-09-04 05:39:14 EDT
Created attachment 146485 [details]
Screenshot of the old error dialog

This is how the error dialog looks with PDE 3.5 if a CoreException occurs in AbstractPDELaunchConfiguration.launch().
Comment 20 Achim Demelt CLA 2009-09-04 05:40:56 EDT
Created attachment 146486 [details]
Screenshot of new error dialog

This is how the error dialog looks after the changes, i.e. by simply re-throwing the CoreException. I'd say this is even better than before, because the user can now jump to the error log directly.
Comment 21 Chris Aniszczyk CLA 2009-09-04 10:23:15 EDT
(In reply to comment #18)
> Created an attachment (id=146484) [details]
> Updated patch

Awesome, applied pde.launching segments.

> Is that what you had in mind? If so, I'll continue with this strategy for the
> other responsibilities of the IPDELauncherSettings. I'd appreciate if you
> committed the changes from this patch into the pde.launching incubator. This
> helps me isolate upcoming changes.

This is exactly what I had in mind. The status handler approach in debug was made for this use case.

> Please note that I failed to come up with a situation that produces returnValue
> == 15, i.e. a failed launch because of a workspace in use. It seems that PDE
> catches this error _before_ the application is actually launched.

This shouldn't be that hard to reproduce. We catch this before the application is launched as it's quicker to catch the error that way (checking for a workspace lock using equinox APIs)

> I've also changed the bundle version to 3.6.0. Since the API classes have benn
> moved into the launching bundle, bug #265699 seems to require that we must not
> start with 1.0.0.

That's fine.

Thanks for your hard work Achim!
Comment 22 Achim Demelt CLA 2009-09-07 10:19:50 EDT
Created attachment 146606 [details]
Updated patch

This updated version uses IStatusHandlers exclusively. No more IPDELauncherSettings and other helper interfaces. The only new API we now introduce is a new constant in IPDELaunchererConstants. 

My tests were all positive. The UI still behaves as expected.

If you approve these changes, I'll move the remaining classes from o.e.pde.launching.launcher to o.e.pde.ui.launcher tomorrow.
Comment 23 Chris Aniszczyk CLA 2009-09-07 11:34:59 EDT
We're looking better :)

One problem I still see is this:

IPDELauncherConstants.java
JUnitLaunchConfigurationDelegate.java
PDESourcePathProvider.java

These classes should be in org.eclipse.pde.ui.launcher in the org.eclipse.pde.launching bundle in order to not break API.

Introducing a new constant is fine.
Comment 24 Chris Aniszczyk CLA 2009-09-07 11:35:50 EDT
I committed modifications to org.eclipse.pde.launching, please attach a new patch when ready.

We are getting close to review time :)
Comment 25 Achim Demelt CLA 2009-09-08 09:54:53 EDT
Created attachment 146662 [details]
(Hopefully) final patch

I moved the remaining classes o.e.pde.ui.launcher. Both bundle versions are now 3.6.0 because or the new constant declaration. I guess we're ready for review now. :-)

One final quirk maybe: the IPDELauncherConstants interface declares a number of IDs for the tabs in the UI. The o.e.pde.launching bundle is not the right place for them to be, but we can't remove them since they're API. You may, however, want to deprecate them and move them to another location.
Comment 26 Chris Aniszczyk CLA 2009-09-08 10:53:34 EDT
We will do this in M3, M2 is next week and there's not enough time but the last patch is looking good.

We will look at releasing this early in M3 after we get PMC approval for the new plug-in.
Comment 27 Chris Aniszczyk CLA 2009-09-08 14:37:25 EDT
Created attachment 146687 [details]
org.eclipse.pde.ui.patch

An update patch.
Comment 28 Chris Aniszczyk CLA 2009-09-21 14:31:18 EDT
Created attachment 147722 [details]
org.eclipse.pde.patch

The final patch.
Comment 29 Chris Aniszczyk CLA 2009-09-21 14:33:29 EDT
Darin, can you give this one a review?

This takes the approach of deprecating the old classes and extending the new ones.
Comment 30 Chris Aniszczyk CLA 2009-09-21 14:39:45 EDT
Achim, can you also verify this latest patch meets your needs?
Comment 31 Chris Aniszczyk CLA 2009-09-21 14:51:58 EDT
Created attachment 147726 [details]
org.eclipse.pde.ui.patch

I made the patch smaller by committing changes to org.eclipse.pde.launching already.
Comment 32 Achim Demelt CLA 2009-09-22 03:02:07 EDT
(In reply to comment #30)
> Achim, can you also verify this latest patch meets your needs?


I locally built Buckminster against the o.e.pde.launching bundle from the pde repo (not the pde-incubator) and tried some headless launching. Everything still worked perfectly. We're good to go from my side.
Comment 33 Chris Aniszczyk CLA 2009-09-22 10:51:57 EDT
(In reply to comment #32)
> I locally built Buckminster against the o.e.pde.launching bundle from the pde
> repo (not the pde-incubator) and tried some headless launching. Everything
> still worked perfectly. We're good to go from my side.

Thanks Achim. 

I'm currently waiting for PMC approval in bug 290054 for the new plug-in. If you have any comments there, please let them be known.
Comment 34 Darin Wright CLA 2009-09-22 12:13:53 EDT
There is a reference to a 1.5 method (easily fixed), in LauncherUtilsStatusHandler, by using "new Integer(...)" instead:

* The method valueOf(String) in the type Integer is not applicable for the arguments (int)

There are API compatbility problems reported by API tooling that are valid. Some class hierachies have been modified (reduced), such that "instanceof" checks would no longer work. For example:

ui.launcher.EclipseApplicationLaunchConfiguration, no longer subclasses ui.launcher.Abstract.AbstractPDELaunchConfiguration.
Comment 35 Chris Aniszczyk CLA 2009-09-22 12:20:09 EDT
(In reply to comment #34)
> There is a reference to a 1.5 method (easily fixed), in
> LauncherUtilsStatusHandler, by using "new Integer(...)" instead:
> 
> * The method valueOf(String) in the type Integer is not applicable for the
> arguments (int)

Sure, I can fix that.

> There are API compatbility problems reported by API tooling that are valid.
> Some class hierachies have been modified (reduced), such that "instanceof"
> checks would no longer work. For example:
> 
> ui.launcher.EclipseApplicationLaunchConfiguration, no longer subclasses
> ui.launcher.Abstract.AbstractPDELaunchConfiguration.

What's the solution here? Are people really doing instanceof checks on these API classes?
Comment 36 Darin Wright CLA 2009-09-22 13:08:01 EDT
(In reply to comment #35)
> What's the solution here? Are people really doing instanceof checks on these
> API classes?

Clients should to migrate to the new classes, but to be compatible, we need leave the old *leaf* classes as is (was). I will attach a patch with a solution. This is unfortunate, but is the best I can come up with.
Comment 37 Darin Wright CLA 2009-09-22 13:08:52 EDT
Created attachment 147800 [details]
patch

Fixes compatibility issues in the old/deprecated classes.
Comment 38 Darin Wright CLA 2009-09-22 13:09:42 EDT
I'll +1 this, adding Chris for review now :-)
Comment 39 Chris Aniszczyk CLA 2009-09-22 13:42:14 EDT
Created attachment 147804 [details]
org.eclipse.pde.patch

I just updated some javadoc in Darin's latest patch.

+1 for inclusion
Comment 40 Chris Aniszczyk CLA 2009-09-22 14:56:47 EDT
done.

Thanks for your help Achim in getting this through.

> 20090922
Comment 41 Achim Demelt CLA 2009-09-23 12:40:07 EDT
> 
> Thanks for your help Achim in getting this through.
> 

You're very welcome. Thanks for accepting this not-so-trivial refactoring. I'd also like to thank Sebastian for helping me getting things started.

We're now finally able to run JUnit tests in headless builds with Buckminster and thus ultimately with b3, too. Now I'll go and reward myself with a beer in the hotel lobby. :-)