Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to handle dynamic dependencies at run-time?
How to handle dynamic dependencies at run-time? [message #467457] Fri, 04 May 2007 06:07 Go to next message
Gerald Rosenberg is currently offline Gerald RosenbergFriend
Messages: 106
Registered: July 2009
Senior Member
I have a plugin that has a JDT dependency needed only to support an
isolated Java editor specific function. Would like to use the plugin in
a Ruby development RCP that does not have the JDT installed (the Java
function is not needed in this case).

Is there any resonable way to detect the absence of the JDT and
exclude/disable the dependence at run-time? Any way short of having two
different static versions of the plugin?

What is the best approach to handling this circumstance?

Thanks,
Gerald
Re: How to handle dynamic dependencies at run-time? [message #467465 is a reply to message #467457] Fri, 04 May 2007 08:51 Go to previous messageGo to next message
Volker is currently offline VolkerFriend
Messages: 8
Registered: July 2009
Junior Member
Gerald Rosenberg wrote:
> I have a plugin that has a JDT dependency needed only to support an
> isolated Java editor specific function. Would like to use the plugin in
> a Ruby development RCP that does not have the JDT installed (the Java
> function is not needed in this case).
>
> Is there any resonable way to detect the absence of the JDT and
> exclude/disable the dependence at run-time? Any way short of having two
> different static versions of the plugin?
>
> What is the best approach to handling this circumstance?
>
> Thanks,
> Gerald

How about making your dependency optional?
Re: How to handle dynamic dependencies at run-time? [message #467485 is a reply to message #467465] Fri, 04 May 2007 13:30 Go to previous messageGo to next message
Gerald Rosenberg is currently offline Gerald RosenbergFriend
Messages: 106
Registered: July 2009
Senior Member
In article <f1es71$8sj$1@build.eclipse.org>, nosp@m.please.org says...
> Gerald Rosenberg wrote:
> > I have a plugin that has a JDT dependency needed only to support an
> > isolated Java editor specific function. Would like to use the plugin in
> > a Ruby development RCP that does not have the JDT installed (the Java
> > function is not needed in this case).
> >
> > Is there any resonable way to detect the absence of the JDT and
> > exclude/disable the dependence at run-time? Any way short of having two
> > different static versions of the plugin?
> >
> > What is the best approach to handling this circumstance?
> >
> > Thanks,
> > Gerald
>
> How about making your dependency optional?
>

How would that be done? An implementation hint would be appreciated.
Re: How to handle dynamic dependencies at run-time? [message #467548 is a reply to message #467485] Sun, 06 May 2007 20:39 Go to previous messageGo to next message
Volker is currently offline VolkerFriend
Messages: 8
Registered: July 2009
Junior Member
Gerald Rosenberg wrote:
> In article <f1es71$8sj$1@build.eclipse.org>, nosp@m.please.org says...
>> Gerald Rosenberg wrote:
>>> I have a plugin that has a JDT dependency needed only to support an
>>> isolated Java editor specific function. Would like to use the plugin in
>>> a Ruby development RCP that does not have the JDT installed (the Java
>>> function is not needed in this case).
>>>
>>> Is there any resonable way to detect the absence of the JDT and
>>> exclude/disable the dependence at run-time? Any way short of having two
>>> different static versions of the plugin?
>>>
>>> What is the best approach to handling this circumstance?
>>>
>>> Thanks,
>>> Gerald
>> How about making your dependency optional?
>>
>
> How would that be done? An implementation hint would be appreciated.

No implementation needed here. In the manifest-Editor, under
'Dependencies' right-click the dependency to be made optional. You'll
see a check-box that does the trick.

Hope that helps.

Cheers, Volker
Re: How to handle dynamic dependencies at run-time? [message #467552 is a reply to message #467548] Mon, 07 May 2007 07:33 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
You can also do the same thing with:

Require-Bundle: com.example.blah;resolution:=optional
Import-Package: com.example.foo;resolution:=optional


Though the IDE does the same thing when you drive it from the GUI.

Alex.
Re: How to handle dynamic dependencies at run-time? [message #467566 is a reply to message #467457] Mon, 07 May 2007 14:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Thu, 03 May 2007 23:07:04 -0700, Gerald Rosenberg wrote:

> I have a plugin that has a JDT dependency needed only to support an
> isolated Java editor specific function. Would like to use the plugin in
> a Ruby development RCP that does not have the JDT installed (the Java
> function is not needed in this case).
>
> Is there any resonable way to detect the absence of the JDT and
> exclude/disable the dependence at run-time? Any way short of having two
> different static versions of the plugin?
>
> What is the best approach to handling this circumstance?
>
> Thanks,
> Gerald

If you do not want two different static plugins, then you will have to
abstract out the difference. This is normally done by using a standard
interface that can be dynamically populated by the dependency if your
tests show the dependency is available.
Re: How to handle dynamic dependencies at run-time? [message #467571 is a reply to message #467552] Mon, 07 May 2007 15:06 Go to previous messageGo to next message
Gerald Rosenberg is currently offline Gerald RosenbergFriend
Messages: 106
Registered: July 2009
Senior Member
In article <2079759.1178523217398.JavaMail.root@cp1.javalobby.org>,
alex_blewitt@yahoo.com says...
> You can also do the same thing with:
>
>
> Require-Bundle: com.example.blah;resolution:=optional
> Import-Package: com.example.foo;resolution:=optional
> 

>
> Though the IDE does the same thing when you drive it from the GUI.
>
> Alex.
>

Volker & Alex --

Exactly what I needed. Very much appreciated.

Best,
Gerald
Re: How to handle dynamic dependencies at run-time? [message #467615 is a reply to message #467548] Wed, 09 May 2007 05:56 Go to previous messageGo to next message
Gerald Rosenberg is currently offline Gerald RosenbergFriend
Messages: 106
Registered: July 2009
Senior Member
In article <f1ledf$p5q$1@build.eclipse.org>, nosp@m.please.org says...
> Gerald Rosenberg wrote:
> > In article <f1es71$8sj$1@build.eclipse.org>, nosp@m.please.org says...
> >> Gerald Rosenberg wrote:
> >>> I have a plugin that has a JDT dependency needed only to support an
> >>> isolated Java editor specific function. Would like to use the plugin in
> >>> a Ruby development RCP that does not have the JDT installed (the Java
> >>> function is not needed in this case).
> >>>
> >>> Is there any resonable way to detect the absence of the JDT and
> >>> exclude/disable the dependence at run-time? Any way short of having two
> >>> different static versions of the plugin?
> >>>
> >>> What is the best approach to handling this circumstance?
> >>>
> >>> Thanks,
> >>> Gerald
> >> How about making your dependency optional?
> >>
> >
> > How would that be done? An implementation hint would be appreciated.
>
> No implementation needed here. In the manifest-Editor, under
> 'Dependencies' right-click the dependency to be made optional. You'll
> see a check-box that does the trick.

Ok, I have
1) the JDT plugins marked optional in the manifest
2) all of the JDT dependent code isolated in a single class 'DocUtils'
3) the plugin class contains a single reference to DocUtils:

// check to see if the JDT is installed & obtain reference
DocUtils docUtils = null;
try {
docUtils = new DocUtils();
} catch (RuntimeException e) {
e.printStackTrace();
}


However, any attempt to load the plugin in an RCP without JDT installed
results in a ClassNotFoundException on the plugin class itself; the
plugin class never even begins execution. When run in Eclipse, the
plugin loads and executes as expected.

So, what am I missing?

Thanks,
Gerald
Re: How to handle dynamic dependencies at run-time? [message #467619 is a reply to message #467615] Wed, 09 May 2007 08:05 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
OK, to check out the dependencies, start up your RCP application with -console -noExit and then use 'ss'. Your bundle, if it can't start, will be in INSTALLED status rather than RESOLVED or ACTIVE.

There will be a number next to it; you can do 'diag 123' to find out what dependencies are missing. It won't say which optional ones are missing, but it will show you which mandatory ones are missing if it's INSTALLED.

You can also do 'start 123' to see if you can bring it up; you'll see any exception generated.

Note that if an exception occurs in the Plugin's start() method -- like an unexpected NullPointerException -- then your bundle will automatically stop itself afterwards.

Alex.
Re: How to handle dynamic dependencies at run-time? [message #467632 is a reply to message #467615] Wed, 09 May 2007 10:55 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
Correct me if I'm wrong but optional only means that the plugin doesn't
have to be available at runtime in order to resolve a bundel but as soon
as you call a class that uses code from the optional bundel eclipse will
try to load it. Unable to find it it will throw a ClassNotFoundException.
I think what you need to do is check if the JDT Bundle is available and
only call into the bundel if it is. If not don't call into the
optional bundle.

Or as mentioned in this thread put the optional functionaliy in a
separate plugin which is optional and make sure you never call into it
as long as it is not needed.

Regards
Stefan



Gerald Rosenberg schrieb:
> In article <f1ledf$p5q$1@build.eclipse.org>, nosp@m.please.org says...
>> Gerald Rosenberg wrote:
>>> In article <f1es71$8sj$1@build.eclipse.org>, nosp@m.please.org says...
>>>> Gerald Rosenberg wrote:
>>>>> I have a plugin that has a JDT dependency needed only to support an
>>>>> isolated Java editor specific function. Would like to use the plugin in
>>>>> a Ruby development RCP that does not have the JDT installed (the Java
>>>>> function is not needed in this case).
>>>>>
>>>>> Is there any resonable way to detect the absence of the JDT and
>>>>> exclude/disable the dependence at run-time? Any way short of having two
>>>>> different static versions of the plugin?
>>>>>
>>>>> What is the best approach to handling this circumstance?
>>>>>
>>>>> Thanks,
>>>>> Gerald
>>>> How about making your dependency optional?
>>>>
>>> How would that be done? An implementation hint would be appreciated.
>> No implementation needed here. In the manifest-Editor, under
>> 'Dependencies' right-click the dependency to be made optional. You'll
>> see a check-box that does the trick.
>
> Ok, I have
> 1) the JDT plugins marked optional in the manifest
> 2) all of the JDT dependent code isolated in a single class 'DocUtils'
> 3) the plugin class contains a single reference to DocUtils:
>
> // check to see if the JDT is installed & obtain reference
> DocUtils docUtils = null;
> try {
> docUtils = new DocUtils();
> } catch (RuntimeException e) {
> e.printStackTrace();
> }
>
>
> However, any attempt to load the plugin in an RCP without JDT installed
> results in a ClassNotFoundException on the plugin class itself; the
> plugin class never even begins execution. When run in Eclipse, the
> plugin loads and executes as expected.
>
> So, what am I missing?
>
> Thanks,
> Gerald
>
Re: How to handle dynamic dependencies at run-time? [message #467648 is a reply to message #467632] Wed, 09 May 2007 16:01 Go to previous messageGo to next message
Gerald Rosenberg is currently offline Gerald RosenbergFriend
Messages: 106
Registered: July 2009
Senior Member
In article <16744865.1178697961875.JavaMail.root@cp1.javalobby.org>,
alex_blewitt@yahoo.com says...
> OK, to check out the dependencies, start up your RCP application with -console -noExit and then use 'ss'. Your bundle, if it can't start, will be in INSTALLED status rather than RESOLVED or ACTIVE.

The RCP is the Aptana Web IDE. The console appears to have been co-
opted: it only shows with the title Aptana Scripting Console and does
not show/allow an osgi command line. Appears to hardwire the console
port to Firefox.

In article <f1s9a9$a0u$1@build.eclipse.org>, mailtolanger@googlemail.com
says...
> Correct me if I'm wrong but optional only means that the plugin doesn't
> have to be available at runtime in order to resolve a bundel but as soon
> as you call a class that uses code from the optional bundel eclipse will
> try to load it. Unable to find it it will throw a ClassNotFoundException.

Trying to catch the obvious 'RuntimeException', 'NullPointerException',
'MissingResourceException', 'BundleException' and even just plain
'Exception' exceptions do not work. But, 'NoClassDefFoundError'
*does*!.

Appears all is good.


> I think what you need to do is check if the JDT Bundle is available and
> only call into the bundel if it is. If not don't call into the
> optional bundle.

Is there a preferred way to directly check if the JDT Bundle is
available? Is there any reason not to just catch the
NoClassDefFoundError and set a flag?

Thanks,
Gerald
Re: How to handle dynamic dependencies at run-time? [message #467654 is a reply to message #467648] Wed, 09 May 2007 17:51 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
If your start method (directly or indirectly) refers to YourDependentClass (and/or you have it as a static reference somewhere) then it won't start up.

NB None of the exceptions you listed will catch NoClassDefFoundError, on account of it being a subclass of Error and not Exception.

You can, with clever coding, set it up such that the code is instantiated at runtime with or without the appropriate utils by providing some kind of Facade. For example:

start()
 helper = helper.instantiate();

abstract class helper
  instantiate = try {
       return Class.forName("dependent.helper").newInstance()
  } catch (Throwable e )
    return null;
  }

dependent.helper extends helper
  doStuff() {
    JDTUTils.doStuff()
  }
}


But it's much better to separate that out into a separate bundle if you can.

Alex.
Re: How to handle dynamic dependencies at run-time? [message #467696 is a reply to message #467648] Thu, 10 May 2007 07:57 Go to previous message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
Gerald Rosenberg schrieb:
>> I think what you need to do is check if the JDT Bundle is available and
>> only call into the bundel if it is. If not don't call into the
>> optional bundle.
>
> Is there a preferred way to directly check if the JDT Bundle is
> available? Is there any reason not to just catch the
> NoClassDefFoundError and set a flag?
As far as I am concerned this is ok but I don't like using exception to
handle control flow if there is another way.

I would try to ask the bundle registry directly.
Example code not tested:
Bundle bundle = Platform.getBundler(<id of the plugin for JDT that you
are calling into>)
if(bundle != null) // this means it has been resolved
{
// do your work her
}

Regards
Stefan
Previous Topic:Changing size of my Workbench
Next Topic:XML TreeViewer - can't get the labels
Goto Forum:
  


Current Time: Sat Apr 20 06:11:32 GMT 2024

Powered by FUDForum. Page generated in 0.03465 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top