Submenu on method level for custom launcher in RCP client - eclipse

I have written a custom launcher in Eclipse which I can access via the "Run As" and "Debug As" on class level. I have a similar configuration as described in How do I use "org.eclipse.debug.ui.launchShortcuts"?. Unfortunately I can't see the submenu in the package explorer at the method level (for example submenu to launch the customer launcher in order to execute a single JUnit test). How can I do this?

JUnit uses a contextualLaunch based on the selected element being a org.eclipse.jdt.core.IJavaElement rather than just a resource. You will need to do the same.
This is what JUnit uses:
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.jdt.core.IJavaElement">
<and>
<test property="org.eclipse.jdt.core.isInJavaProject"/>
<or>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="junit.framework.Test"/>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="org.junit.platform.commons.annotation.Testable"/>
</or>
<test property="org.eclipse.jdt.junit.canLaunchAsJUnit" forcePluginActivation="true"/>
</and>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
Some of the <test elements are specific to JUnit so you will need to use something different.

Related

Eclipse Plugin: what property attribut for testing name of subversion resources

I'm writing a plugin. To start it, the menu entry is displayed when doing a rightclick on a project in SVN-Plugin-View. By using "org.tigris.subversion.subclipse.ui.repository.RepositoriesView" as locationURI inside the plugin.xml my menu entry is visible, as I wanted.
But now I want to make it visible under special conditions. I don't find out, what property I can use to test the name of the Project.
I already did something similar inside Eclipse with
<command...
<visible when>
<with variable="activeMenuSelection">
<iterate ifEmpty="false">
<adapt type="org.eclipse.core.resources.IProject">
<test property="org.eclipse.core.resources.name" value="Test_*"/>
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
Now I use
but I don't find out what to use as test property
Like in my working (without SVN) example I tried
<test property="org.tigris.subversion.subclipse.core.resources.name" value="Test_*/>"
But it did not work. The menu entry was not visible for SVN-Projects with names starting with "Test_"

"adapt" in visibleWhen for menuContribution always returns false

I am trying to follow Lars Vogel's tutorial on natures and am stuck at the point where the visibleWhen for a menu is defined. When I add the following to my command definition in my menuContribution:
<visibleWhen
checkEnabled="false">
<adapt
type="org.eclipse.core.resources.IProject">
</adapt>
</visibleWhen>
my menu item never appears when right-clicking a project in Project Explorer.
I double-checked that I have all necessary things like org.eclipse.core.runtime, org.eclipse.core.resources and org.eclipse.ui as dependencies.
What am I missing?
You need to use <iterate> since what you are testing is a selection which may have multiple items:
For example this is one of the PDE API analysis tool command definitions:
<command
commandId="org.eclipse.pde.api.tools.ui.convert.javadocs"
style="push">
<visibleWhen
checkEnabled="false">
<iterate>
<adapt
type="org.eclipse.core.resources.IProject">
<test
property="org.eclipse.core.resources.projectNature"
value="org.eclipse.pde.api.tools.apiAnalysisNature">
</test>
</adapt>
</iterate>
</visibleWhen>
</command>

Command Expression for active debug session?

I added the extension point org.eclipse.ui.menus to create a new button in the debug view.
That works perfectly, but this particular button is now always visible. How can I add a visibleWhen condition that checks if a debug session is currently running?
I checked the Command Core Expressions, but did not find any expressions that may work in that case.
The menus in the org.eclipse.jdt.debug.ui plugin use expressions like this:
<visibleWhen
checkEnabled="false">
<and>
<systemTest
property="org.eclipse.jdt.debug.ui.debuggerActive"
value="true">
</systemTest>
... other tests ...
</and>
</visibleWhen>
There is a good example project in CDT on how to get started customizing DSF. Please have a look at it's plugin.xml and follow the uses of the command id defined there: org.eclipse.cdt.examples.dsf.gdb.command.showVersion
Here is one of the visibleWhen's from that code.
<visibleWhen
checkEnabled="false">
<and>
<reference
definitionId="org.eclipse.cdt.debug.ui.testIsDebugActionSetActive">
</reference>
<with variable="org.eclipse.core.runtime.Platform">
<test property="org.eclipse.core.runtime.bundleState"
args="org.eclipse.cdt.examples.dsf.gdb"
value="ACTIVE">
</test>
</with>
</and>
</visibleWhen>

Contribute to Eclipse context menu when file and parent project meet conditions

I want to contribute a context menu only when the following 2 conditions are met:
1.- If selected file has .txt extension
2.- If parent project of the selected file has an specific facet
I can do this by separate using the following conditions using the org.eclipse.ui.menus extension point, i.e: for the project facet:
<with variable="activeMenuSelection">
<iterate operator="and" ifEmpty="false">
<adapt type="org.eclipse.core.resources.IProject">
<test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="jst.code.quality" forcePluginActivation="true" />
</adapt>
</iterate>
</with>
And for the file extension:
<with variable="activeMenuSelection">
<iterate operator="and" ifEmpty="false">
<adapt type="org.eclipse.core.resources.IFile">
<test property="org.eclipse.core.resources.extension" value="txt" forcePluginActivation="true" />
</adapt>
</iterate>
</with>
But I have problems to combine this two conditions since the activeMenuSelection variable will only contain the file and I can't use it to test the project facet, is there a variable I can use to access the active project in the same condition?
The org.eclipse.wst.common.project.facet.core.projectFacet test will work on any IResource so it will work on an IFile as well as an IProject. So you can combine the tests.

Use of ILaunchConfigurationMigrationDelegate

I do not understand how migration of Eclipse Launch Configrations (ILaunchConfiguration) works. In my dreams, I'd love to have the following:
My plugin, version 1.0, is used to create a Launch Configuration referencing file something_1.0/foo
The plugin is upgraded to version 2.0, which also deletes the file still referenced in all old launch configurations of the plugin
The old launch configurations are automatically upgraded so that something_2.0/foo is referenced instead of the non-existing something_1.0/foo
Step 3 sadly is the one that does not work, although I wrote and connected a corresponding implementation of ILaunchConfigurationMigrationDelegate. It seems the code is never executed.
When exactly are configurations migrated? According to the code, there is a Migrate button, which I cannot find. According to the documentation configurations might be migrated automatically. How is this triggered?
Thanks,
Carsten
This implementation of this interface should be declared in extension point.
You can refer to JDT itself implementation org.eclipse.jdt.internal.launching.JavaMigrationDelegate.
Please note the launch shortcut specify the configuration type as the one defined via extension.
<extension
point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
class="org.eclipse.jdt.debug.ui.launchConfigurations.JavaApplicationLaunchShortcut"
description="%JavaLaunchShortcut.description"
helpContextId="org.eclipse.jdt.debug.ui.shortcut_local_java_application"
icon="$nl$/icons/full/etool16/java_app.gif"
id="org.eclipse.jdt.debug.ui.localJavaShortcut"
label="%JavaApplicationShortcut.label"
modes="run, debug">
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<and>
<adapt type="org.eclipse.jdt.core.IJavaElement">
<test property="org.eclipse.jdt.core.isInJavaProject"/>
</adapt>
<or>
<test property="org.eclipse.jdt.launching.hasMain"/>
<test property="org.eclipse.jdt.launching.isContainer"/>
<test property="org.eclipse.jdt.launching.isPackageFragment"/>
<test property="org.eclipse.jdt.launching.isPackageFragmentRoot"/>
</or>
</and>
</iterate>
</with>
</enablement>
</contextualLaunch>
<configurationType
id="org.eclipse.jdt.launching.localJavaApplication">
</configurationType>
<description
description="%RunJavaLaunchShortcut.description"
mode="run">
</description>
<description
description="%DebugJavaLaunchShortcut.description"
mode="debug">
</description>
</shortcut>