Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "ETrice/Development/Tips and tricks"

(New page: = General Eclipse HOWTOs = == Add Tracing to Your Plug-in == code format="Java" private static boolean traceData = false; static { if (Activator.getDefault().isDebugging()) { ...)
 
(Add Tracing to Your Plug-in)
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
== Add Tracing to Your Plug-in ==
 
== Add Tracing to Your Plug-in ==
  
[[code format="Java"]]
+
Add a file <code>.option</code> on the top level of your plug-in project. To this file add a line
 +
<pre>
 +
de.protos.example/trace/data=true
 +
</pre>
 +
 
 +
This setting can be toggled in the trace tab of your launch configuration (it's also possible to edit string values there).
 +
 
 +
Here is the source code that uses these settings to enable trace messages printed to system log or standard out:
 +
 
 +
<source lang="Java">
 
private static boolean traceData = false;
 
private static boolean traceData = false;
  
Line 14: Line 23:
 
}
 
}
 
}
 
}
[[code]]
+
</source>
 +
 
 +
You may have to define an Activator class if it's not present yet. In the MANIFEST.MF make sure that the plug-in is activated when one of its classes is loaded.
 +
The Activator may be derived from AbstractUIPlugin and should in its minimal version look like this:
 +
 
 +
<source lang="Java">
 +
 
 +
public class Activator extends AbstractUIPlugin implements BundleActivator {
 +
 
 +
private static Activator instance = null;
 +
 +
public static Activator getDefault() {
 +
return instance;
 +
}
 +
 +
@Override
 +
public void start(BundleContext context) throws Exception {
 +
super.start(context);
 +
instance = this;
 +
}
 +
 +
@Override
 +
public void stop(BundleContext context) throws Exception {
 +
instance = null;
 +
super.stop(context);
 +
}
 +
}
 +
</source>

Revision as of 10:47, 31 July 2012

General Eclipse HOWTOs

Add Tracing to Your Plug-in

Add a file .option on the top level of your plug-in project. To this file add a line

de.protos.example/trace/data=true

This setting can be toggled in the trace tab of your launch configuration (it's also possible to edit string values there).

Here is the source code that uses these settings to enable trace messages printed to system log or standard out:

	private static boolean traceData = false;
 
	static {
		if (Activator.getDefault().isDebugging()) {
			String value = Platform.getDebugOption(
					"de.protos.example/trace/data");
			if (value!=null && value.equalsIgnoreCase(Boolean.toString(true)))
				traceData = true;
		}
	}

You may have to define an Activator class if it's not present yet. In the MANIFEST.MF make sure that the plug-in is activated when one of its classes is loaded. The Activator may be derived from AbstractUIPlugin and should in its minimal version look like this:

public class Activator extends AbstractUIPlugin implements BundleActivator {
 
	private static Activator instance = null;
 
	public static Activator getDefault() {
		return instance;
	}
 
	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		instance = this;
	}
 
	@Override
	public void stop(BundleContext context) throws Exception {
		instance = null;
		super.stop(context);
	}
}

Copyright © Eclipse Foundation, Inc. All Rights Reserved.