Search code examples
eclipsemaventycho

Run tycho eclipse plugin as Eclipse Application


I just created an eclipse plugin using tycho. I can run mvn clean install and so far there are no errors.

Now I want to run the plugin as Eclipse Application (it is basically a builder). When I press run as Eclipse Application a second eclipse instance is showing up. When I create a new project there and add my builder, eclipse throws me this exception:

org.eclipse.e4.core.di.InjectionException: org.eclipse.core.commands.ExecutionException: Failed to toggle nature

Caused by: org.eclipse.core.commands.ExecutionException: Failed to toggle nature

Caused by: org.eclipse.core.runtime.CoreException: Problems encountered while setting project description

The error happens in this method:

   private void toggleNature(IProject project) throws CoreException {

        IProjectDescription description = project.getDescription();
        String[] natures = description.getNatureIds();

        for (int i = 0; i < natures.length; ++i) {
            if (SidecarNature.NATURE_ID.equals(natures[i])) {
                // Remove the nature
                String[] newNatures = new String[natures.length - 1];
                System.arraycopy(natures, 0, newNatures, 0, i);
                System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
                description.setNatureIds(newNatures);
                project.setDescription(description, null);
                return;
            }
        }

        // Add the nature
        String[] newNatures = new String[natures.length + 1];
        System.arraycopy(natures, 0, newNatures, 0, natures.length);
        newNatures[natures.length] = SidecarNature.NATURE_ID;
        description.setNatureIds(newNatures);


        // ---------------------------------------
        // The Error is thrown here
        // ---------------------------------------
        project.setDescription(description, null);
    }

I don't know whats wrong since this is the eclipse template code. I haven't changed anything. It should works when I dont use maven.

This is basically the pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
 <modelVersion>4.0.0</modelVersion>  
 <groupId>tycho_example</groupId>  
 <artifactId>com.codeandme.tycho.plugin</artifactId>  
 <version>1.0.0-SNAPSHOT</version>  
 <packaging>eclipse-plugin</packaging>  

 <properties>  
  <tycho.version>0.23.0</tycho.version>  
 </properties>  

 <repositories>  
  <!-- add Mars repository to resolve dependencies -->  
  <repository>  
   <id>Mars</id>  
   <layout>p2</layout>  
   <url>http://download.eclipse.org/releases/mars/</url>  
  </repository>  
 </repositories>  

 <build>  
  <plugins>  
   <plugin>  
    <!-- enable tycho build extension -->  
    <groupId>org.eclipse.tycho</groupId>  
    <artifactId>tycho-maven-plugin</artifactId>  
    <version>${tycho.version}</version>  
    <extensions>true</extensions>  
   </plugin>  
  </plugins>  
 </build>  
</project> 

Edit As requested here is the full stack trace:

org.eclipse.e4.core.di.InjectionException: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:68)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:252)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:234)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
    at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
    at org.eclipse.core.commands.Command.executeWithChecks(Command.java:493)
    at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:486)
    at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:799)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:675)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:659)
    at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:592)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4230)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1491)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1514)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1499)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1299)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4072)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3698)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: org.eclipse.core.commands.ExecutionException: Failed to toggle nature
    at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.execute(AddRemoveSidewiseNatureHandler.java:37)
    at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295)
    at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
    ... 41 more
Caused by: org.eclipse.core.runtime.CoreException: Problems encountered while setting project description.
    at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1256)
    at org.eclipse.core.internal.resources.Project.setDescription(Project.java:1281)
    at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.toggleNature(AddRemoveSidewiseNatureHandler.java:78)
    at de.ustutt.sidewise.eclipseintegration.builder.AddRemoveSidewiseNatureHandler.execute(AddRemoveSidewiseNatureHandler.java:34)
    ... 48 more

Edit2 The IStatus:

Status WARNING: org.eclipse.core.resources code=568 Problems encountered while setting project description. null children=[[type: WARNING], [path: null], [message: Nature does not exist: eclipseintegration.builder.SidewiseNature.], [plugin: org.eclipse.core.resources], [exception: null]
]

Solution

  • The message in the IStatus Nature does not exist: eclipseintegration.builder.SidewiseNature. is saying you are trying to add a nature that does not exist.

    Have you declared the nature with the org.eclipse.core.resources.natures extension point? Does the id declared there match the SidecarNature.NATURE_ID constant?