`

Eclipse插件开发面试题

阅读更多

Question: [Plugin]When does a plugin get started?
Question: [Plugin]How to config a plugin to start automatically during platform starts up?
Question:  [Plugin]What are extensions and extension points?
Question:  [Plugin]What is the classpath of a plug-in?
Question:  [SWT]How to access UI objects from a non-ui thread?
Question:  [SWT]Do we need to explicitly invoke org.eclipse.swt.graphics.Image.dispose()?
Question:  [SWT]How to fire a key event in my test code to make the program act as if a user pressed a key?
Question: [SWT]What is Display, what is Shell?
Question: [SWT]Why do I get the error "org.eclipse.swt.SWTException: Invalid thread access"?
Question: [SWT]How to resize my shell to get my changed widgets to lay out again?
Question: [EMF]What is EMF?
Question: [EMF]Is there a built-in facility to check whether a given value is valid compared to the effective facets of its type?
Question: [RCP]What is included in the Rich Client Platform?
Question: [RCP]How can I change the window icon in my application?
Question: [ExtensionPoint]How can I hide menu contributed by other plugins?
Question: [OSGI]What are the differences between 'Require-Bundle' and 'Import-Package'
Question: [OSGI]What is optional dependency
Question: [TEST]How to write unit test for eclpse plugin

Q: When does a plugin get started?
A: Each plug-in can be viewed as having a declarative section and a code section. The declarative part is contained in the plugin.xml file. This file is loaded into a registry when the platform starts up and so is always available, regardless of whether a plug-in has started. The code section are laze loaded by default. They are activated only when their functionality has been explicitly invoked by the user.
.
 
 
Q: How to config a plugin to start automatically during platform starts up?
A: Define the 'Eclipse-AutoStart=true' header in Manifest file.
.
 
 
Q: What are extensions and extension points?
A: Loose coupling in Eclipse is achieved partially through the mechanism of extensions and extension points. When a plug-in wants to allow other plug-ins to extend or customize portions of its functionality, it will declare an extension point. 
The extension point declares a typically a combination of XML markup and Java interfaces, that extensions must conform to. Plug-ins that want to connect to that extension point must implement that contract in their extension. 

The key attribute is that the plug-in being extended knows nothing about the plug-in that is connecting to it beyond the scope of that extension point contract. This allows plug-ins built by different individuals or companies to interact seamlessly, even without their knowing much about one another. 
.
 
 
Q: What is the classpath of a plug-in?
A: The OSGi parent class loader. (Java boot class loader by default); The exported libraries of all imported plug-ins; The declared libraries of the plug-in and all its fragments. 
 
 
Q: How to access UI objects from a non-ui thread?
A: Use Display.getDefault().asyncExec(new Runnable()...) Display.asyncExec causes the run() method of the runnable to be invoked by the user-interface thread at the next reasonable opportunity. The caller of this method continues to run in parallel, and is not notified when the runnable has completed. 
 
 
Q: Do we need to explicitly invoke org.eclipse.swt.graphics.Image.dispose()?
A: Application code must explicitly invoke the Image.dispose() method to release the operating system resources managed by each instance when those instances are no longer required. This is because that the Java finalization is too weak to reliably support management of operating system resources.
 
 
Q: How to fire a key event in my test code to make the program act as if a user pressed a key?
A: Two ways to implement it in code: generating OS level key event use Display.post(Event) or use Widge.notifyListeners(...) to just notify a widget's listeners.
 
Q: What is Display, what is Shell?
A: The Display class respresents the GUI process(thread), the Shell class represents windows.
 
Q: Why do I get the error "org.eclipse.swt.SWTException: Invalid thread access"?
A: SWT implements a single-threaded UI model often called apartment threading. In this model, only the UI-thread can invoke UI operations. SWT strictly enforces this rule. If you try and access an SWT object from outside the UI-thread, you get the exception "org.eclipse.swt.SWTException: Invalid thread access".
The following code sets the text of a label from a background thread and waits for the operation to complete: display.syncExec( new Runnable() { public void run(){ label.setText(text); } });
 
 
Q: How to resize my shell to get my changed widgets to lay out again?
A: A layout is only performed automatically on a Composite's children when the Composite is resized, including when it is initially shown. To make a Composite lay out its children under any other circumstances, such as when children are created or disposed, its layout() method must be called.
 
 
Q: What is EMF?
A: The Eclipse Modeling Framework is a Java/XML framework for generating tools and other applications based on simple class models. EMF helps you rapidly turn models into efficient, correct, and easily customizable Java code. It is intended to provide the benefits of formal modeling, but with a very low cost of entry. In addition to code generation, it provides the ability to save objects as XML documents for interchange with other tools and applications. 

Models can be created using annotated Java, XML documents, or modeling tools like Rational Rose, then imported into EMF. The code generator turns a model into a set of Java implementation classes. These classes are extensible and regenerable - you can modify them by adding user-defined methods and instance variables. When the model changes, you can regenerate the implementation classes, and your modifications will be retained. This works both ways - changes in the Java code can be used to update the model.
 
 
Q: Is there a built-in facility to check whether a given value is valid compared to the effective facets of its type?
A: To determine if a literal is valid with respect to a simple type, you can use either XSDSimpleTypeDefinition.isValidLiteral or XSDSimpleTypeDefinition.assess.
 
 
Q: What is included in the Rich Client Platform?
A: Eclipse Runtime, SWt, JFace, Workbench 
 
 
Q: How can I change the window icon in my application?
A: Define a product via the products extension point and specify the windowImages property to refer to two image files, a 16x16 one and a 32x32 one.
 
 
Q: How can I hide menu contribued by other plugins?
A: We can use org.eclipse.ui.activities extension to hide menu from other plugin

<extension point="org.eclipse.ui.activities">

<activity id="com.xyz.Activity" 
description="Menus contributions from com.xyz" 
name="My Activity" />

<category id="com.xyz.Category" 
description="com.xyz Activities" 
name="My Category">

<!-- put the activity in the category --> ><categoryActivityBinding activityId="com.xyz.Activity"
categoryId="com.xyz.Category"
/>

<!-- bind all contributions from plugin com.xyz -->
<activityPatternBinding id="com.xyz.Activity"
pattern="com\.xyz/.*"/>

<!-- menu activity from xyz plugin will be be disabled by default -->
</extension>


 
 
Q: [OSGI]What are the differences between 'Require-Bundle' and 'Import-Package'
A: There are two complementary ways of depending on something from outside a given plug-in; Require-Bundle and Import-Package. 

Using the Require-Bundle manifest header, plug-ins specify an explicit dependency on a specific bundle and version. As such, the required bundles are placed logically on the dependent plug-in's classpath. 

Import-Package is used to declare a dependency on a package without knowing which exact bundle will provide it. Any bundle in the environment must export the package with Export-Package for the Import-Package to be resolved.

 
 
Q: [OSGI]What is optional dependency
A: plug-in prerequisite elements can be made optional by adding the optional="true" attribute in Manifest file(see below for an example). Marking an import as optional simply states that if the specified plug-in is not found at runtime, the dependent plug-in should be left enabled. 

This is used when a plug-in can be used in many scenarios or it is reasonable to operate with reduced function. It allows the creation of minimal installs that cover functional subsets. 
Require-Bundle: org.eclipse.swt; optional="true" 
 
 
Q: [TEST]How to write unit test for eclipse plugin
A: Use Eclipse plugin fragments to develop PDE Unit tests for each plugin. 
Two ways to run the unit test:
  • Use JUnit Plug-in Test Launcher to test in GUI
  • Use PDE headless build to integrate into the automatic build and test environment.
  • 分享到:
    评论

    相关推荐

    Global site tag (gtag.js) - Google Analytics