Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipse-dev] Problem Adding NatureIds to JavaProjects

I am creating a plugin in eclipse 2.1.1 that will create a template project for developers. It will create all the directories and files needed for a simple project saving the time it takes to copy an existing project over and initializing everything. I am having problems adding a Nature Id to a project when I try to set the updated project description in the existing project


The extension point in my plugin.xml is as follows:




    name="BusConnector Nature"










The method in question is:


  public static void addNatureToProject( IProject project, String natureId ) throws CoreException


    Log.debug( "BusPlugin.addNatureToProject(" + project + ", " + natureId + ")" );


    IProject proj = project.getProject();

    Log.debug( "BusPlugin.addNatureToProject() got project '" + proj + "'" );


    // Add nature only if it is not already there

    if( !proj.hasNature(natureId) )


      Log.debug( "BusPlugin.addNatureToProject() adding nature '" + natureId + "' to " + project );

      IProjectDescription description = proj.getDescription();

      String[] currentNatures = description.getNatureIds();

      String[] newNatures = new String[currentNatures.length + 1];

      System.arraycopy( currentNatures, 0, newNatures, 0, currentNatures.length );

      newNatures[currentNatures.length] = natureId;

      description.setNatureIds( newNatures );



        StringBuffer buf = new StringBuffer("Project status:\r\n");

        buf.append(" isAccessible: ");buf.append( proj.isAccessible());buf.append( "\r\n");

        buf.append(" isDerived: ");buf.append( proj.isDerived());buf.append( "\r\n");

        buf.append(" isLinked: ");buf.append( proj.isLinked());buf.append( "\r\n");

        buf.append(" isLocal: ");buf.append( proj.isLocal(0));buf.append( "\r\n");

        buf.append(" isNatureEnabled: ");buf.append( proj.isNatureEnabled(natureId));buf.append( "\r\n");

        buf.append(" isOpen: ");buf.append( proj.isOpen());buf.append( "\r\n");

        buf.append(" isPhantom: ");buf.append( proj.isPhantom());buf.append( "\r\n");

        buf.append(" isReadOnly: ");buf.append( proj.isReadOnly());buf.append( "\r\n");

        buf.append(" isSynchronized: ");buf.append( proj.isSynchronized(0));buf.append( "\r\n");

        buf.append(" isTeamPrivateMember: ");buf.append( proj.isTeamPrivateMember());buf.append( "\r\n");

        Log.debug( buf.toString() );


        proj.setDescription( description, null );

        Log.debug( "BusPlugin.addNatureToProject() there are now "+newNatures.length+" current natures" );


      catch (CoreException e)


        Log.err("D'oh! "+e.getMessage());






      Log.debug( "BusPlugin.addNatureToProject() nature '" + natureId + "' is already associated to this project" );






And here is the log that I'm generating:


DEBUG[30524:0] main | Thu Sep 18 14:35:12 EDT 2003 | BusProject.setting nature id 'com.qwest.bus.busnature'

DEBUG[30524:0] main | Thu Sep 18 14:35:12 EDT 2003 | BusPlugin.addNatureToProject(P/TestProject, com.qwest.bus.busnature)

DEBUG[30524:0] main | Thu Sep 18 14:35:12 EDT 2003 | BusPlugin.addNatureToProject() got project 'P/TestProject'

DEBUG[30534:10] main | Thu Sep 18 14:35:12 EDT 2003 | BusPlugin.addNatureToProject() adding nature 'com.qwest.bus.busnature' to P/TestProject

DEBUG[30544:10] main | Thu Sep 18 14:35:12 EDT 2003 | Project status:

 isAccessible: true

 isDerived: false

 isLinked: false

 isLocal: true

 isNatureEnabled: false

 isOpen: true

 isPhantom: false

 isReadOnly: false

 isSynchronized: true

 isTeamPrivateMember: false


ERROR[30544:0] main | Thu Sep 18 14:35:12 EDT 2003 | D'oh! Problems encountered while setting project description.

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

      at org.eclipse.core.internal.resources.Project.setDescription(

      at org.eclipse.core.internal.resources.Project.setDescription(

      at com.qwest.bus.BusPlugin.addNatureToProject(

      at com.qwest.bus.BusProject.addBusNatureToProject(

      at com.qwest.bus.BusProjectCreationWizard.performFinish(

      at org.eclipse.jface.wizard.WizardDialog.finishPressed(





What am I missing / doing wrong?


Thanks in advance for any help received.



-Steve Coté


Back to the top