Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Possible to deduce plugin from object instance
Possible to deduce plugin from object instance [message #88711] Sun, 27 May 2007 02:01 Go to next message
Eclipse UserFriend
Originally posted by: expires07.logular.com

Is it possible to deduce the Eclipse plugin that is associated with an
object instance? If so, how?

Background: I'd like to enhance my tracing routine (shown below) to avoid
passage of the plugin parameter. A new implementation would determine
the correct plugin ID internally.

Thanks for any tips,

Jason.

/**
* Return true if the passed object (or an ancestor) is currently being
traced.
*/
public static boolean isTracing(Plugin plugin, Object tracer) {
if (plugin == null || plugin.getBundle() == null || !
plugin.isDebugging()) {
return false;
}

String className = getClassName(tracer);

Boolean enabled = (Boolean)classNameFlagMap.get(className);
if (enabled == null) {
String pluginId = plugin.getBundle().getSymbolicName()
+"/";
String name = className;
while (name.length() > 0) {
String option = Platform.getDebugOption(pluginId
+name);
// ascend the outer class and package hierarchy
to see if one of these
// "parents" is enabled.
if (option == null) {
int index = name.lastIndexOf('.');
if (index > 0) {
name = name.substring(0, index);
}
else {
break;
}
}
else {
enabled = Boolean.valueOf(option);
break;
}
}
if (enabled == null) {
System.err.println("Tracing is not configured for
"+className+"\n" +
"The project's .options file needs an entry
like: \n "+
pluginId + className + " = false");
enabled = Boolean.FALSE;
}
classNameFlagMap.put(className, enabled);
}
return enabled.booleanValue();
}
Re: Possible to deduce plugin from object instance [message #88727 is a reply to message #88711] Sun, 27 May 2007 11:33 Go to previous messageGo to next message
Richard Backhouse is currently offline Richard BackhouseFriend
Messages: 19
Registered: July 2009
Junior Member
Jason,

One way would be to keep a map of all the bundle classloaders and their
symbolic names. When your bundle is started you can find all the loaded
bundles via the BundleContext.getBundles() method. You would have to
also listen for bundle events to be notified when bundles are added and
removed. The symbolic name of the bundle is the plugin id. You could
then use :

obj.getClass().getClassLoader();

to obtain the classloader for the object being logged. Finding the
plugin id would then be a lookup on the classloader against the map.

Richard

Jason Grant wrote:
> Is it possible to deduce the Eclipse plugin that is associated with an
> object instance? If so, how?
>
> Background: I'd like to enhance my tracing routine (shown below) to avoid
> passage of the plugin parameter. A new implementation would determine
> the correct plugin ID internally.
>
> Thanks for any tips,
>
> Jason.
>
> /**
> * Return true if the passed object (or an ancestor) is currently being
> traced.
> */
> public static boolean isTracing(Plugin plugin, Object tracer) {
> if (plugin == null || plugin.getBundle() == null || !
> plugin.isDebugging()) {
> return false;
> }
>
> String className = getClassName(tracer);
>
> Boolean enabled = (Boolean)classNameFlagMap.get(className);
> if (enabled == null) {
> String pluginId = plugin.getBundle().getSymbolicName()
> +"/";
> String name = className;
> while (name.length() > 0) {
> String option = Platform.getDebugOption(pluginId
> +name);
> // ascend the outer class and package hierarchy
> to see if one of these
> // "parents" is enabled.
> if (option == null) {
> int index = name.lastIndexOf('.');
> if (index > 0) {
> name = name.substring(0, index);
> }
> else {
> break;
> }
> }
> else {
> enabled = Boolean.valueOf(option);
> break;
> }
> }
> if (enabled == null) {
> System.err.println("Tracing is not configured for
> "+className+"\n" +
> "The project's .options file needs an entry
> like: \n "+
> pluginId + className + " = false");
> enabled = Boolean.FALSE;
> }
> classNameFlagMap.put(className, enabled);
> }
> return enabled.booleanValue();
> }
>
>
Re: Possible to deduce plugin from object instance [message #88741 is a reply to message #88711] Sun, 27 May 2007 17:36 Go to previous message
Simon Kaegi is currently offline Simon KaegiFriend
Messages: 381
Registered: July 2009
Senior Member
Take a look at the PackageAdmin service.
I think what you're looking for is the getBundle method.

http://www2.osgi.org/javadoc/r4/org/osgi/service/packageadmi n/PackageAdmin.html#getBundle

HTH
-Simon

"Jason Grant" <expires07@logular.com> wrote in message
news:f3aoqc$qfn$1@build.eclipse.org...
> Is it possible to deduce the Eclipse plugin that is associated with an
> object instance? If so, how?
>
> Background: I'd like to enhance my tracing routine (shown below) to avoid
> passage of the plugin parameter. A new implementation would determine
> the correct plugin ID internally.
>
> Thanks for any tips,
>
> Jason.
>
> /**
> * Return true if the passed object (or an ancestor) is currently being
> traced.
> */
> public static boolean isTracing(Plugin plugin, Object tracer) {
> if (plugin == null || plugin.getBundle() == null || !
> plugin.isDebugging()) {
> return false;
> }
>
> String className = getClassName(tracer);
>
> Boolean enabled = (Boolean)classNameFlagMap.get(className);
> if (enabled == null) {
> String pluginId = plugin.getBundle().getSymbolicName()
> +"/";
> String name = className;
> while (name.length() > 0) {
> String option = Platform.getDebugOption(pluginId
> +name);
> // ascend the outer class and package hierarchy
> to see if one of these
> // "parents" is enabled.
> if (option == null) {
> int index = name.lastIndexOf('.');
> if (index > 0) {
> name = name.substring(0, index);
> }
> else {
> break;
> }
> }
> else {
> enabled = Boolean.valueOf(option);
> break;
> }
> }
> if (enabled == null) {
> System.err.println("Tracing is not configured for
> "+className+"\n" +
> "The project's .options file needs an entry
> like: \n "+
> pluginId + className + " = false");
> enabled = Boolean.FALSE;
> }
> classNameFlagMap.put(className, enabled);
> }
> return enabled.booleanValue();
> }
>
>
Previous Topic:ProxyServlet finds registered servlet for invalid url!?
Next Topic:Bundle Activator packaged in embedded jar
Goto Forum:
  


Current Time: Wed Jan 15 11:15:11 GMT 2025

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

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

Back to the top