예제 #1
0
  /**
   * Creates CDT project in a specific path in workspace adding specified configurations and opens
   * it.
   *
   * @param projectName - project name.
   * @param pathInWorkspace - path relative to workspace root.
   * @param configurationIds - array of configuration IDs.
   * @return - new {@link IProject}.
   * @throws CoreException - if the project can't be created.
   * @throws OperationCanceledException...
   */
  public static IProject createCDTProject(
      String projectName, String pathInWorkspace, String[] configurationIds)
      throws OperationCanceledException, CoreException {
    CCorePlugin cdtCorePlugin = CCorePlugin.getDefault();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();

    IProject project = root.getProject(projectName);
    IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER);
    resourcesCreated.add(project);

    IProjectDescription prjDescription = workspace.newProjectDescription(projectName);
    if (pathInWorkspace != null) {
      IPath absoluteLocation = root.getLocation().append(pathInWorkspace);
      prjDescription.setLocation(absoluteLocation);
    }

    if (configurationIds != null && configurationIds.length > 0) {
      ICProjectDescriptionManager prjDescManager = cdtCorePlugin.getProjectDescriptionManager();

      project.create(NULL_MONITOR);
      project.open(NULL_MONITOR);

      ICProjectDescription icPrjDescription =
          prjDescManager.createProjectDescription(project, false);
      ICConfigurationDescription baseConfiguration =
          cdtCorePlugin.getPreferenceConfiguration(TestCfgDataProvider.PROVIDER_ID);

      for (String cfgId : configurationIds) {
        icPrjDescription.createConfiguration(cfgId, cfgId + " Name", baseConfiguration);
      }
      prjDescManager.setProjectDescription(project, icPrjDescription);
    }
    project = cdtCorePlugin.createCDTProject(prjDescription, project, NULL_MONITOR);
    waitForProjectRefreshToFinish();
    Assert.assertNotNull(project);

    project.open(null);
    Assert.assertTrue(project.isOpen());

    return project;
  }
예제 #2
0
 /**
  * Searches in the prj for the config description with the same ID as for given cfg. If there's no
  * such cfgd, it will be created.
  *
  * @param prj - project description where we'll search (or create) config description
  * @param cfg - config description belonging to another project description, it is a sample for
  *     search and base for possile creation of resulting configuration description.
  * @return the configuration description (found or created) or null in case of error
  */
 private ICConfigurationDescription findCfg(
     ICProjectDescription prj, ICConfigurationDescription cfg) {
   String id = cfg.getId();
   // find config with the same ID as original one
   ICConfigurationDescription c = prj.getConfigurationById(id);
   // if there's no cfg found, try to create it
   if (c == null) {
     try {
       c = prj.createConfiguration(id, cfg.getName(), cfg);
       c.setDescription(cfg.getDescription());
     } catch (CoreException e) {
       /* do nothing: c is already null */
     }
   }
   // if creation failed, report an error and return null
   if (c == null) {
     MessageBox mb = new MessageBox(getShell());
     mb.setMessage(Messages.AbstractPage_3);
     mb.open();
   }
   return c;
 }