| Possible to deduce plugin from object instance [message #88711] | 
Sat, 26 May 2007 22:01   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 #88741 is a reply to message #88711] | 
Sun, 27 May 2007 13:36   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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(); 
> } 
> 
>
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.03654 seconds