How to handle dynamic dependencies at run-time? [message #467457] |
Fri, 04 May 2007 02:07  |
Eclipse User |
|
|
|
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 #467615 is a reply to message #467548] |
Wed, 09 May 2007 01:56   |
Eclipse User |
|
|
|
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 #467632 is a reply to message #467615] |
Wed, 09 May 2007 06:55   |
Eclipse User |
|
|
|
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 12:01   |
Eclipse User |
|
|
|
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 #467696 is a reply to message #467648] |
Thu, 10 May 2007 03:57  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05279 seconds