Use of ILaunchConfigurationMigrationDelegate - eclipse

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>

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_"

Submenu on method level for custom launcher in RCP client

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.

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.

Call JUnit from other Eclipse Plugin

I am developing for Eclipse, and one feature is run JUnit tests. Now my plugin detect JUnit tests on a project in workspace and after this I want to call JUnit to run this tests.
I heard about ILaunch, ILaunchConfigurationDelegate, JUnitLaunchConfigurationDelegate but I cannot found an example of this and also I'm not sure if I have to use this!
-- Thanks in advance
Please see my answer to How does Eclipse actually run Junit tests?. You will need to create a Run Configuration and then call JUnitLaunchConfigurationDelegate#launch() with the configuration.
The easiest way to do this is to add shortcuts to the extension point org.eclipse.debug.ui.launchShortcuts. With the correct configurationType, you can create the correct type and normally, Eclipse will do the rest. In fact this is exactly what we've done in the Scala IDE.
Here is the relevant XML from scala-ide:
<extension point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
label="%JUnitShortcut.label"
icon="$nl$/icons/full/obj16/julaunch.gif"
helpContextId="org.eclipse.jdt.junit.launch_shortcut"
class="org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut"
modes="run, debug"
id="scala.tools.eclipse.scalatest.junitShortcut">
<contextualLaunch>
<enablement>
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.jdt.core.IJavaElement">
<test property="org.eclipse.debug.ui.matchesPattern" value="*.scala"/>
<test property="org.eclipse.jdt.core.isInJavaProject"/>
<test property="org.eclipse.jdt.core.hasTypeOnClasspath" value="junit.framework.Test"/>
<or>
<test property="scala.tools.eclipse.launching.canLaunchAsJUnit" forcePluginActivation="true"/>
<test property="scala.tools.eclipse.launching.junit.canLaunchAsJUnit" forcePluginActivation="true"/>
</or>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
<configurationType
id="org.eclipse.jdt.junit.launchconfig">
</configurationType>
<description
description="%DebugJUnitLaunchShortcut.description"
mode="debug">
</description>
<description
description="%RunJUnitLaunchShortcut.description"
mode="run">
</description>
</shortcut>
</extension>
The important element is the <contextualLaunch>, which defines a set of tests which need to be true in order that the option to launch as JUnit be presented to the user. Most of these are self explanatory, but we've also scala.tools.eclipse.launching.canLaunchAsJUnit, which references an extension point org.eclipse.core.expressions.propertyTesters. These property testers test whether the code can be launched as JUnit or not (for instance, the class under test extends TestCase or whatever).
If you need more details, I recommend downloading Scala IDE, and looking at the code, but it is written in Scala.
I rewrote part of launche junit services, then inform the project it calls the debug and run.
See my implementation to call the JUnitLaunch