I have developed a simple plugin to generate some routine code. This plugin has a contribution to a popup menu of Package Explorer. It is working as intended when running from the development environment (Launch as Eclipse application from Eclipse RCP) — an appropriate menu item appears in the menu, and its invocation does what is expected.
However, I’m having a hard time deploying it into a different Eclipse instance.
The developed plugin was exported with Export Wizard, which produced a separate jar file. This jar file has been placed into the dropings directory of another Eclipse installation (newly unpackaged). When this Eclipse instance launches, the popup menu of Package Explorer does not contain the contributed menu item. The information from Eclipse Installation Details shows that the plugin is present on the Plug-Ins tab, and the Configuration tab has it listed as tg.companion (1.0.0.201208132302) "Companion Object Generator" [Starting].
What am I missing? Why the contributed menu item does not show up?
Thanx.
The locationURI for the menu contribution is popup:org.eclipse.jdt.ui.PackageExplorer, the value for property allPopups is true.
The plugin is unsigned.
Here’s the plugin files that might shed some light.
Plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="tg.companion.handler.generator"
label="TG Create Companion Object"
style="push"
tooltip="Creates a companion object to the selected entity object, and provides DAO/RAO implementations">
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="tg.companion.handler.GenerateCompanionObjects"
id="tg.companion.handler.generator"
name="Generate Comanion">
</command>
</extension>
</plugin>
MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Companion Object Generator
Bundle-SymbolicName: tg.companion;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: tg.companion.Activator
Bundle-Vendor: TG
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jdt.core;bundle-version="3.8.1",
org.eclipse.core.resources;bundle-version="3.8.0",
org.eclipse.core.expressions;bundle-version="3.4.400"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Command handler:
package tg.companion.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
public class GenerateCompanionObjects extends AbstractHandler implements IHandler {
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final Shell shell = HandlerUtil.getActiveShell(event);
final ISelection sel = HandlerUtil.getActiveMenuSelection(event);
final IStructuredSelection selection = (IStructuredSelection) sel;
final Object firstElement = selection.getFirstElement();
if (firstElement instanceof ICompilationUnit) {
createOutput(shell, (ICompilationUnit) firstElement);
} else {
MessageDialog.openWarning(shell, "Companion Object Generation Warning", "Please select an entity object for generating a corresponding companion.");
}
return null;
}
private void createOutput(final Shell shell, final ICompilationUnit cu) {
// does code generation work using Java Model
}
}
Finally, the problem has been solved!
After careful review of the project structure it was identified that build.properties file (for some reason) did not have plugin.xml checked. As the result, plugin.xml was not included into the produced by the export wizard jar file.
Once the build.properties files has been amended to include plugin.xml, the resulting jar file had it included and deployed without any issues.
Interestingly, the plugin export wizard did not even warn about the exclusion of plugin.xml, which I would personally have expected.