Skip to main content

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


The eclipse.platform newsgroup would be an appropriate place to ask questions like this.  This mailing list is for discussion about the implementation of Eclipse itself.  (Hint: the CoreException contains a MultiStatus, and its children will tell you what the problem is).
--



"Cote, Steve" <steve.cote@xxxxxxxxx>
Sent by: eclipse-dev-admin@xxxxxxxxxxx

09/18/2003 02:45 PM
Please respond to eclipse-dev

       
        To:        "'eclipse-dev@xxxxxxxxxxx'" <eclipse-dev@xxxxxxxxxxx>
        cc:        
        Subject:        [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:
 
  <extension
    id="com.qwest.bus.busnature"
    name="BusConnector Nature"
    point="org.eclipse.core.resources.natures">
    <runtime>
      <run
        class="com.qwest.bus.BusProject">
      </run>
    </runtime>
  </extension>
 
 
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 );
      try
      {
        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());
        e.printStackTrace();
      }
    }
    else
    {
      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(Project.java:805)
      at org.eclipse.core.internal.resources.Project.setDescription(Project.java:829)
      at com.qwest.bus.BusPlugin.addNatureToProject(BusPlugin.java:228)
      at com.qwest.bus.BusProject.addBusNatureToProject(BusProject.java:170)
      at com.qwest.bus.BusProjectCreationWizard.performFinish(BusProjectCreationWizard.java:168)
      at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:608)
--[snip]--
 
 
 
What am I missing / doing wrong?
 
Thanks in advance for any help received.
 
 
-Steve Coté
 

Back to the top