private ISourceTagProvider createSourceTagProvider(IStorage storage) {
   ITranslationUnit tUnit = null;
   if (storage instanceof IFile) {
     tUnit = (ITranslationUnit) CoreModel.getDefault().create((IFile) storage);
   } else if (storage instanceof IFileState) {
     ICModel cModel = CoreModel.getDefault().getCModel();
     ICProject[] cProjects;
     try {
       cProjects = cModel.getCProjects();
       if (cProjects.length > 0) {
         tUnit =
             CoreModel.getDefault().createTranslationUnitFrom(cProjects[0], storage.getFullPath());
       }
     } catch (CModelException e) {
     }
   } else {
     IEditorInput input = CDTUITools.getEditorInputForLocation(storage.getFullPath(), null);
     if (input != null) {
       tUnit = (ITranslationUnit) input.getAdapter(ITranslationUnit.class);
     }
   }
   if (tUnit != null) {
     return new CSourceTagProvider(tUnit);
   }
   return null;
 }
 private ITranslationUnit getTranslationUnit(IFile file) {
   Object element = CoreModel.getDefault().create(file);
   if (element instanceof ITranslationUnit) {
     return (ITranslationUnit) element;
   }
   return null;
 }
 /**
  * Clone a configuration and put it on the tmp list if it is not already a saved configuration and
  * not already on the tmp list.
  *
  * @param p project
  * @param oldId the id of the old configuration to clone
  * @param cfgd the configuration descriptor for the clone
  * @return true if the configuration is already saved, false otherwise
  */
 public synchronized boolean cloneCfg(IProject p, String oldId, ICConfigurationDescription cfgd) {
   if (isConfigurationAlreadySaved(p, cfgd)) return true;
   Map<String, IAConfiguration> tmpList = getTmpConfigs(p);
   String newId = cfgd.getId();
   // Don't bother if the new configuration is already on the tmp list
   IAConfiguration cfg = tmpList.get(newId);
   if (cfg != null) return false;
   // Otherwise, try and find the old id to copy the configuration from
   // or punt if not found
   IAConfiguration oldCfg = null;
   Map<String, IAConfiguration> savedList = getSavedConfigs(p);
   if (savedList != null) oldCfg = savedList.get(oldId);
   if (oldCfg != null) {
     IAConfiguration newCfg = oldCfg.copy(cfgd.getId());
     tmpList.put(cfgd.getId(), newCfg);
     // Check to see if the new configuration is already stored as part of the project description.
     // If yes, it should already be saved.  This can occur if the configuration was added as part
     // of
     // another CDT Property page and the Autotools Property page was never opened.
     if (CoreModel.getDefault().getProjectDescription(p).getConfigurationById(newId) != null) {
       addConfiguration(p, newCfg);
       return true;
     }
   }
   return false;
 }
 public synchronized void saveConfigs(IProject project) {
   synchronized (project) {
     ICConfigurationDescription[] cfgds =
         CoreModel.getDefault().getProjectDescription(project).getConfigurations();
     saveConfigs(project, cfgds);
   }
 }
示例#5
0
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
  */
 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
   if (this.viewer == null) {
     MakeCorePlugin.getDefault().getTargetManager().addListener(this);
   }
   this.viewer = (StructuredViewer) viewer;
   IWorkspace oldWorkspace = null;
   IWorkspace newWorkspace = null;
   if (oldInput instanceof IWorkspace) {
     oldWorkspace = (IWorkspace) oldInput;
   } else if (oldInput instanceof IContainer) {
     oldWorkspace = ((IContainer) oldInput).getWorkspace();
   } else if (oldInput instanceof TargetSourceContainer) {
     oldWorkspace = ((TargetSourceContainer) oldInput).getContainer().getWorkspace();
   }
   if (newInput instanceof IWorkspace) {
     newWorkspace = (IWorkspace) newInput;
   } else if (newInput instanceof IContainer) {
     newWorkspace = ((IContainer) newInput).getWorkspace();
   } else if (newInput instanceof TargetSourceContainer) {
     newWorkspace = ((TargetSourceContainer) newInput).getContainer().getWorkspace();
   }
   if (oldWorkspace != newWorkspace) {
     ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
     if (oldWorkspace != null) {
       InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID).removePreferenceChangeListener(this);
       mngr.removeCProjectDescriptionListener(this);
       oldWorkspace.removeResourceChangeListener(this);
     }
     if (newWorkspace != null) {
       newWorkspace.addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
       mngr.addCProjectDescriptionListener(this, CProjectDescriptionEvent.APPLIED);
       InstanceScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID).addPreferenceChangeListener(this);
     }
   }
 }
  protected CPElement[] openWorkspacePathEntryDialog(CPElement existing) {
    Class<?>[] acceptedClasses =
        new Class[] {ICProject.class, IProject.class, IContainer.class, ICContainer.class};
    TypedElementSelectionValidator validator =
        new TypedElementSelectionValidator(acceptedClasses, existing == null);
    ViewerFilter filter = new TypedViewerFilter(acceptedClasses);

    String title =
        (existing == null)
            ? CPathEntryMessages.IncludeSymbolEntryPage_fromWorkspaceDialog_new_title
            : CPathEntryMessages.IncludeSymbolEntryPage_fromWorkspaceDialog_edit_title;
    String message =
        (existing == null)
            ? CPathEntryMessages.IncludeSymbolEntryPage_fromWorkspaceDialog_new_description
            : CPathEntryMessages.IncludeSymbolEntryPage_fromWorkspaceDialog_edit_description;

    ElementTreeSelectionDialog dialog =
        new ElementTreeSelectionDialog(
            getShell(), new WorkbenchLabelProvider(), new CElementContentProvider());
    dialog.setValidator(validator);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.addFilter(filter);
    dialog.setInput(CoreModel.getDefault().getCModel());
    if (existing == null) {
      dialog.setInitialSelection(fCurrCProject);
    } else {
      dialog.setInitialSelection(existing.getCProject());
    }

    if (dialog.open() == Window.OK) {
      Object[] elements = dialog.getResult();
      CPElement[] res = new CPElement[elements.length];
      for (int i = 0; i < res.length; i++) {
        IProject project;
        IPath includePath;
        if (elements[i] instanceof IResource) {
          project = ((IResource) elements[i]).getProject();
          includePath = ((IResource) elements[i]).getProjectRelativePath();
        } else {
          project = ((ICElement) elements[i]).getCProject().getProject();
          includePath = ((ICElement) elements[i]).getResource().getProjectRelativePath();
        }
        CPElementGroup group = getSelectedGroup();
        res[i] =
            new CPElement(
                fCurrCProject,
                IPathEntry.CDT_INCLUDE,
                group.getResource().getFullPath(),
                group.getResource());
        res[i].setAttribute(CPElement.BASE, project.getFullPath().makeRelative());
        res[i].setAttribute(CPElement.INCLUDE, includePath);
      }
      return res;
    }
    return null;
  }
  /** @see IncrementalProjectBuilder#build */
  @Override
  protected IProject[] build(
      int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
      throws CoreException {
    if (DEBUG_EVENTS) {
      @SuppressWarnings("unchecked")
      Map<String, String> argsMap = args;
      printEvent(kind, argsMap);
    }

    // If auto discovery is disabled, do nothing
    //		boolean autodiscoveryEnabled;
    //		boolean autodiscoveryEnabled2;
    //		IScannerConfigBuilderInfo2 buildInfo2 = null;
    //		IConfiguration cfg = ScannerConfigUtil.getActiveConfiguration(getProject());
    IManagedBuildInfo bInfo = ManagedBuildManager.getBuildInfo(getProject());
    if (bInfo != null) {
      IConfiguration cfgs[] = bInfo.getManagedProject().getConfigurations();
      if (cfgs.length != 0) {
        if (!needAllConfigBuild()) {
          ICProjectDescription des =
              CoreModel.getDefault().getProjectDescription(getProject(), false);
          IConfiguration cfg = null;
          if (des != null) {
            ICConfigurationDescription settingCfgDes = des.getDefaultSettingConfiguration();
            if (settingCfgDes != null) {
              for (int i = 0; i < cfgs.length; i++) {
                if (settingCfgDes.getId().equals(cfgs[i].getId())) {
                  cfg = cfgs[i];
                  break;
                }
              }
            }
          }
          if (cfg != null) {
            cfgs = new IConfiguration[] {cfg};
          } else {
            cfgs = new IConfiguration[0];
          }
        }
        int numWork = cfgs.length;
        if (numWork > 0) {
          monitor.beginTask(
              MakeMessages.getString("ScannerConfigBuilder.Invoking_Builder"),
              numWork); //$NON-NLS-1$
          for (int i = 0; i < cfgs.length; i++) {
            build(cfgs[i], 0, new SubProgressMonitor(monitor, 1));
          }
        }
      }

      CfgDiscoveredPathManager.getInstance().updateCoreSettings(getProject(), cfgs);
    }

    return getProject().getReferencedProjects();
  }
  public void testCPathEntriesForOldStyle() throws Exception {
    p2 = CProjectHelper.createCCProject(PROJ_NAME_PREFIX + "b", null, IPDOMManager.ID_NO_INDEXER);
    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    IProject project = p2.getProject();
    ICProjectDescription des = mngr.getProjectDescription(project, false);
    assertNotNull(des);
    assertEquals(1, des.getConfigurations().length);
    assertFalse(mngr.isNewStyleProject(des));
    assertFalse(mngr.isNewStyleProject(project));

    IPathEntry[] entries = CoreModel.getRawPathEntries(p2);
    entries =
        concatEntries(
            entries,
            new IPathEntry[] {
              CoreModel.newSourceEntry(project.getFullPath().append("test_src")),
              CoreModel.newOutputEntry(project.getFullPath().append("test_out")),
            });

    CoreModel.setRawPathEntries(p2, entries, null);

    ICSourceEntry[] expectedSourceEntries =
        new ICSourceEntry[] {
          new CSourceEntry(
              project.getFullPath(), new IPath[] {new Path("test_src")}, ICSettingEntry.RESOLVED),
          new CSourceEntry(project.getFullPath().append("test_src"), null, ICSettingEntry.RESOLVED),
        };

    ICOutputEntry[] expectedOutputEntries =
        new ICOutputEntry[] {
          new COutputEntry(
              project.getFullPath(),
              null,
              ICSettingEntry.RESOLVED | ICSettingEntry.VALUE_WORKSPACE_PATH),
          new COutputEntry(
              project.getFullPath().append("test_out"),
              null,
              ICSettingEntry.RESOLVED | ICSettingEntry.VALUE_WORKSPACE_PATH),
        };

    des = mngr.getProjectDescription(project, false);
    ICConfigurationDescription cfg = des.getDefaultSettingConfiguration();
    ICSourceEntry[] sEntries = cfg.getSourceEntries();
    ICOutputEntry[] oEntries = cfg.getBuildSetting().getOutputDirectories();

    checkCEntriesMatch(expectedSourceEntries, sEntries);
    checkCEntriesMatch(expectedOutputEntries, oEntries);

    des = mngr.getProjectDescription(project, true);
    cfg = des.getDefaultSettingConfiguration();
    sEntries = cfg.getSourceEntries();
    oEntries = cfg.getBuildSetting().getOutputDirectories();

    checkCEntriesMatch(expectedSourceEntries, sEntries);
    checkCEntriesMatch(expectedOutputEntries, oEntries);
  }
示例#9
0
  /**
   * Gets the CDT environment from the CDT project's configuration referenced by the launch
   *
   * @since 3.0
   */
  public static String[] getLaunchEnvironment(ILaunchConfiguration config) throws CoreException {
    // Get the project
    String projectName =
        config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
    if (projectName == null) {
      return null;
    }
    projectName = projectName.trim();
    if (projectName.length() == 0) {
      return null;
    }
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (project == null || !project.isAccessible()) return null;

    ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project, false);

    // Not a CDT project?
    if (projDesc == null) return null;

    String buildConfigID =
        config.getAttribute(
            ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, ""); // $NON-NLS-1$
    ICConfigurationDescription cfg = null;
    if (buildConfigID.length() != 0) cfg = projDesc.getConfigurationById(buildConfigID);

    // if configuration is null fall-back to active
    if (cfg == null) cfg = projDesc.getActiveConfiguration();

    // Environment variables and inherited vars
    HashMap<String, String> envMap = new HashMap<String, String>();
    IEnvironmentVariable[] vars =
        CCorePlugin.getDefault().getBuildEnvironmentManager().getVariables(cfg, true);
    for (IEnvironmentVariable var : vars) envMap.put(var.getName(), var.getValue());

    // Add variables from build info
    ICdtVariable[] build_vars = CCorePlugin.getDefault().getCdtVariableManager().getVariables(cfg);
    for (ICdtVariable var : build_vars) {
      try {
        envMap.put(var.getName(), var.getStringValue());
      } catch (CdtVariableException e) {
        // Some Eclipse dynamic variables can't be resolved dynamically... we don't care.
      }
    }

    // Turn it into an envp format
    List<String> strings = new ArrayList<String>(envMap.size());
    for (Entry<String, String> entry : envMap.entrySet()) {
      StringBuffer buffer = new StringBuffer(entry.getKey());
      buffer.append('=').append(entry.getValue());
      strings.add(buffer.toString());
    }

    return strings.toArray(new String[strings.size()]);
  }
  private ICConfigurationDescription[] getCfgs(IProject prj) {
    ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false);
    if (prjd != null) {
      ICConfigurationDescription[] cfgs = prjd.getConfigurations();
      if (cfgs != null) {
        return cfgs;
      }
    }

    return new ICConfigurationDescription[0];
  }
 /** @see org.eclipse.jface.viewers.IContentProvider#dispose() */
 @Override
 public void dispose() {
   super.dispose();
   if (fListener != null) {
     CoreModel.getDefault().removeElementChangedListener(fListener);
     fListener = null;
   }
   if (fPropertyListener != null) {
     PreferenceConstants.getPreferenceStore().removePropertyChangeListener(fPropertyListener);
     fPropertyListener = null;
   }
 }
  /*
   * @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
   */
  @Override
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    boolean isTU = newInput instanceof ITranslationUnit;

    if (isTU) {
      root = (ITranslationUnit) newInput;
      if (fListener == null) {
        fListener = new ElementChangedListener();
        CoreModel.getDefault().addElementChangedListener(fListener);
        fPropertyListener = new PropertyListener();
        PreferenceConstants.getPreferenceStore().addPropertyChangeListener(fPropertyListener);
      }
    } else {
      if (fListener != null) {
        CoreModel.getDefault().removeElementChangedListener(fListener);
        PreferenceConstants.getPreferenceStore().removePropertyChangeListener(fPropertyListener);
        fListener = null;
        fPropertyListener = null;
      }
      root = null;
    }
  }
  @Override
  public ICConfigurationDescription resolveSelectedConfiguration() {
    ICConfigurationDescription result = null;

    IProject project = resolveProject();
    if (project != null) {
      ICProjectDescription desc = CoreModel.getDefault().getProjectDescription(project);

      if (desc != null) {
        result = desc.getConfigurationById(getSelectedConfigurationID());
      }
    }

    return result;
  }
 /**
  * Synchronize the current set of configurations for the project with the Autotools saved
  * configuration data. This is required when configuration management occurs outside of the
  * Autotools Configure Settings page in the Property menu.
  *
  * @param project to synchronize configurations for
  */
 public synchronized void syncConfigurations(IProject project) {
   setSyncing(true);
   clearTmpConfigurations(project);
   ICProjectDescription pd = CoreModel.getDefault().getProjectDescription(project);
   ICConfigurationDescription[] cfgs = pd.getConfigurations();
   Map<String, IAConfiguration> newCfgList = new HashMap<>();
   for (int i = 0; i < cfgs.length; ++i) {
     cfgs[i].getConfigurationData();
     IAConfiguration acfg = getTmpConfiguration(project, cfgs[i]);
     newCfgList.put(cfgs[i].getId(), acfg);
   }
   setSyncing(false);
   clearTmpConfigurations(project);
   replaceProjectConfigurations(project, newCfgList);
 }
 /*
  * @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#getChildren(java.lang.Object)
  */
 @Override
 public Object[] getChildren(Object element) {
   if (element instanceof IWorkspaceRoot) {
     IWorkspaceRoot root = (IWorkspaceRoot) element;
     IProject[] projects = root.getProjects();
     List<ICProject> list = new ArrayList<ICProject>(projects.length);
     for (int i = 0; i < projects.length; i++) {
       if (CoreModel.hasCNature(projects[i])) {
         list.add(CoreModel.getDefault().create(projects[i]));
       }
     }
     return list.toArray();
   }
   return super.getChildren(element);
 }
 private void initProjects() {
   ArrayList<ICProject> input = new ArrayList<ICProject>();
   ICProject[] projects;
   try {
     projects = CoreModel.getDefault().getCModel().getCProjects();
     for (ICProject project : projects) {
       if (project.getProject().isOpen()) {
         input.add(project);
       }
     }
   } catch (CModelException e) {
     CUIPlugin.log(e);
   }
   fProjectViewer.setInput(input);
 }
 public void resourceChanged(IResourceChangeEvent event) {
   IResourceDelta rootDelta = event.getDelta();
   for (IResourceDelta projectDelta : rootDelta.getAffectedChildren()) {
     for (IResourceDelta fileDelta : projectDelta.getAffectedChildren()) {
       if (fileDelta.getResource().getName().endsWith(".spd.xml")) {
         // Refresh the dynamic C++ include paths in case there has been change to a shared
         // library in
         // the SDR.
         CoreModel.getDefault()
             .getProjectDescriptionManager()
             .updateExternalSettingsProviders(
                 new String[] {ExternalSettingProvider.ID}, new NullProgressMonitor());
       }
     }
   }
 }
  @Override
  public Collection<ICConfigurationDescription> resolveConfigurations() {
    ICConfigurationDescription[] result = null;

    IProject project = resolveProject();
    if (project != null) {
      ICProjectDescription desc = CoreModel.getDefault().getProjectDescription(project);

      if (desc != null) {
        result = desc.getConfigurations();
      }
    }

    return (result == null)
        ? Collections.<ICConfigurationDescription>emptyList()
        : Arrays.asList(result);
  }
示例#19
0
  private boolean isIndexerAffected() {
    ICProjectDescription desc = CoreModel.getDefault().getProjectDescription(getProject(), false);
    if (desc == null || desc.isCdtProjectCreating()) return false;

    Iterator<InternalTab> it = itabs.iterator();
    while (it.hasNext()) {
      InternalTab tab = it.next();
      if (tab != null) {
        ICPropertyTab tabtab = tab.tab;
        if (tabtab instanceof AbstractCPropertyTab
            && ((AbstractCPropertyTab) tabtab).isIndexerAffected()) {
          return true;
        }
      }
    }
    return false;
  }
  @Override
  public void activate() {
    ICConfigurationDescription config = resolveSelectedConfiguration();

    if (config != null) {
      ICProjectDescription desc = config.getProjectDescription();

      if (desc.getActiveConfiguration() != config) {
        try {
          IProject project = desc.getProject();
          desc.setActiveConfiguration(config);
          CoreModel.getDefault().setProjectDescription(project, desc);
        } catch (CoreException e) {
          CUIPlugin.log(e);
        }
      }
    }
  }
	private IFile getFileForPathImpl(IPath path, IProject project) {
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		if (path.isAbsolute()) {
			IFile c = root.getFileForLocation(path);
			return c;
		}
		if (project != null && project.exists()) {
			ICProject cproject = CoreModel.getDefault().create(project);
			if (cproject != null) {
				try {
					ISourceRoot[] roots = cproject.getAllSourceRoots();
					for (ISourceRoot sourceRoot : roots) {
						IResource r = sourceRoot.getResource();
						if (r instanceof IContainer) {
							IContainer parent = (IContainer) r;
							IResource res = parent.findMember(path);
							if (res != null && res.exists() && res instanceof IFile) {
								IFile file = (IFile) res;
								return file;
							}
						}
					}

					IOutputEntry entries[] = cproject.getOutputEntries();
					for (IOutputEntry pathEntry : entries) {
						IPath p = pathEntry.getPath();
						IResource r = root.findMember(p);
						if (r instanceof IContainer) {
							IContainer parent = (IContainer) r;
							IResource res = parent.findMember(path);
							if (res != null && res.exists() && res instanceof IFile) {
								IFile file = (IFile) res;
								return file;
							}
						}
					}
					
				} catch (CModelException _) {
					Activator.getDefault().getLog().log(_.getStatus());
				}
			}
		}
		return null;
	}
  /** @since 1.2 */
  public synchronized Map<String, IAutotoolsOption> getAutotoolsCfgOptions(
      IProject project, String cfgId) throws CoreException {

    // Verify project is valid Autotools project
    if (project == null || !project.hasNature(AutotoolsNewProjectNature.AUTOTOOLS_NATURE_ID)) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              AutotoolsPlugin.PLUGIN_ID,
              ConfigureMessages.getString(INVALID_AUTOTOOLS_PROJECT)));
    }

    // Verify configuration id is valid
    ICConfigurationDescription cfgd =
        CoreModel.getDefault().getProjectDescription(project).getConfigurationById(cfgId);
    IConfiguration icfg = ManagedBuildManager.getConfigurationForDescription(cfgd);
    if (icfg == null) {
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              AutotoolsPlugin.PLUGIN_ID,
              ConfigureMessages.getString(INVALID_AUTOTOOLS_CONFIG_ID)));
    }

    IAConfiguration cfg = getConfiguration(project, cfgId);
    HashMap<String, IAutotoolsOption> options = new HashMap<>();

    // Get set of configuration options and convert to set of IAutotoolOptions
    Map<String, IConfigureOption> cfgOptions = cfg.getOptions();
    IAConfiguration dummyCfg = createDefaultConfiguration(createDummyId());
    for (Iterator<Entry<String, IConfigureOption>> i = cfgOptions.entrySet().iterator();
        i.hasNext(); ) {
      Map.Entry<String, IConfigureOption> entry = i.next();
      String name = entry.getKey();
      IAutotoolsOption configOption =
          new AutotoolsOption(entry.getValue().copy((AutotoolsConfiguration) dummyCfg));
      options.put(name, configOption);
    }

    return options;
  }
  /** @deprecated Not intended to be public - do not use */
  @Deprecated
  public String getDefaultDebugger(final ILaunchConfiguration config) throws CoreException {
    // Mostly from CDebbuggerTab
    String defaultDebugger = null;

    String projectName =
        config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
    if (projectName.length() > 0) {
      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
      ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project);
      if (projDesc != null) {
        ICConfigurationDescription configDesc = projDesc.getActiveConfiguration();
        String configId = configDesc.getId();
        ICDebugConfiguration[] debugConfigs =
            CDebugCorePlugin.getDefault().getActiveDebugConfigurations();
        outer:
        for (int i = 0; i < debugConfigs.length; ++i) {
          ICDebugConfiguration debugConfig = debugConfigs[i];
          String[] patterns = debugConfig.getSupportedBuildConfigPatterns();
          if (patterns != null) {
            for (int j = 0; j < patterns.length; ++j) {
              if (configId.matches(patterns[j])) {
                defaultDebugger = debugConfig.getID();
                break outer;
              }
            }
          }
        }
      }
    }

    if (defaultDebugger == null) {
      ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration();
      if (dc != null) {
        defaultDebugger = dc.getID();
      }
    }

    return defaultDebugger;
  }
  private void initLanguageSettings(IProject project) throws CoreException {
    ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);

    if (prjDesc == null) throw new IllegalArgumentException("No valid CDT project given!");

    ICConfigurationDescription activeConfig = prjDesc.getActiveConfiguration();

    if (activeConfig == null)
      throw new IllegalArgumentException("No valid active configuration found!");

    String[] extensionsToInclude = getExtensionsToInclude(project);
    ICFolderDescription folderDesc = activeConfig.getRootFolderDescription();

    for (ICLanguageSetting ls : folderDesc.getLanguageSettings()) {
      String[] extensions = ls.getSourceExtensions();
      Arrays.sort(extensions);

      if (Arrays.equals(extensionsToInclude, extensions)) {
        languageSettings.add(ls);
      }
    }
  }
  public DiscoveredScannerInfo getDiscoveredScannerInfo(IProject project, boolean cacheInfo)
      throws CoreException {
    DiscoveredScannerInfo scannerInfo = null;
    // See if there's already one associated with the resource for this
    // session
    scannerInfo = (DiscoveredScannerInfo) project.getSessionProperty(scannerInfoProperty);

    if (scannerInfo == null) {
      scannerInfo = new DiscoveredScannerInfo(project);
      // this will convert user info
      org.eclipse.cdt.make.core.MakeScannerInfo makeScannerInfo =
          org.eclipse.cdt.make.core.MakeScannerProvider.getDefault()
              .getMakeScannerInfo(project, cacheInfo);
      scannerInfo.setUserScannerInfo(makeScannerInfo);

      // migrate to new C Path Entries
      IContainerEntry container = CoreModel.newContainerEntry(DiscoveredPathContainer.CONTAINER_ID);
      ICProject cProject = CoreModel.getDefault().create(project);
      if (cProject != null) {
        IPathEntry[] entries = cProject.getRawPathEntries();
        List<IPathEntry> newEntries = new ArrayList<IPathEntry>(Arrays.asList(entries));
        if (!newEntries.contains(container)) {
          newEntries.add(container);
          cProject.setRawPathEntries(newEntries.toArray(new IPathEntry[newEntries.size()]), null);
        }
      }
      ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project);
      descriptor.remove(
          CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID); // remove scanner provider which will fallback to
      // default
      // cpath provider.
      // place holder to that we don't convert again.
      project.setSessionProperty(scannerInfoProperty, scannerInfo);
    }
    return scannerInfo;
  }
示例#26
0
 private void rebuildIndex() {
   final Shell shell = getShell();
   final String title = getTitle();
   final String msg = Messages.AbstractPage_rebuildIndex_question;
   int result =
       OptionalMessageDialog.open(
           PREF_ASK_REINDEX,
           shell,
           title,
           null /* default image */,
           msg,
           MessageDialog.QUESTION,
           new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL},
           0);
   if (result == OptionalMessageDialog.NOT_SHOWN) {
     result = OptionalMessageDialog.getDialogDetail(PREF_ASK_REINDEX);
   } else if (result != SWT.DEFAULT) {
     OptionalMessageDialog.setDialogDetail(PREF_ASK_REINDEX, result);
   }
   if (result == 0) { // first button
     final IProject project = getProject();
     CCorePlugin.getIndexManager().reindex(CoreModel.getDefault().create(project));
   }
 }
示例#27
0
  /**
   * Test getting and updating configuration options for an Autotools Project. The top-level
   * contains autogen.sh which will build configure, but not run it.
   *
   * @throws Exception
   */
  public void testGetAndUpdateConfigureOptions() throws Exception {
    Path p = new Path("zip/project2.zip");
    ProjectTools.addSourceContainerWithImport(testProject, "src", p, null);
    assertTrue(testProject.hasNature(ManagedCProjectNature.MNG_NATURE_ID));
    ProjectTools.setConfigDir(testProject, "src");
    ProjectTools.markExecutable(testProject, "src/autogen.sh");
    assertTrue(ProjectTools.build());
    ICConfigurationDescription cfgDes =
        CoreModel.getDefault().getProjectDescription(testProject).getActiveConfiguration();
    IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);
    assertTrue(cfg.getName().equals("Build (GNU)"));
    Map<String, IAutotoolsOption> opts =
        AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId());
    IAutotoolsOption configdir = opts.get(AutotoolsOptionConstants.OPT_CONFIGDIR);
    assertEquals(configdir.getType(), IAutotoolsOption.INTERNAL);
    assertTrue(configdir.getValue().equals("src"));
    assertTrue(configdir.canUpdate());
    // Verify we cannot update any of the categories or flags
    IAutotoolsOption k = opts.get(AutotoolsOptionConstants.CATEGORY_DIRECTORIES);
    assertFalse(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.CATEGORY);

    k = opts.get(AutotoolsOptionConstants.CATEGORY_FEATURES);
    assertFalse(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.CATEGORY);

    k = opts.get(AutotoolsOptionConstants.CATEGORY_FILENAMES);
    assertFalse(k.canUpdate());

    k = opts.get(AutotoolsOptionConstants.CATEGORY_GENERAL);
    assertEquals(k.getType(), IAutotoolsOption.CATEGORY);
    assertFalse(k.canUpdate());

    k = opts.get(AutotoolsOptionConstants.CATEGORY_OPTIONS);
    assertEquals(k.getType(), IAutotoolsOption.CATEGORY);
    assertFalse(k.canUpdate());

    k = opts.get(AutotoolsOptionConstants.CATEGORY_PLATFORM);
    assertFalse(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.CATEGORY);

    k = opts.get(AutotoolsOptionConstants.FLAG_CFLAGS);
    assertFalse(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.FLAG);

    // Tools are ok to update
    k = opts.get(AutotoolsOptionConstants.TOOL_AUTOGEN);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.TOOL);
    assertEquals(k.getValue(), "autogen.sh"); // $NON-NLS-1$
    k.setValue("autogen2.sh"); // $NON-NLS-1$

    k = opts.get(AutotoolsOptionConstants.TOOL_CONFIGURE);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.TOOL);
    assertEquals(k.getValue(), "configure"); // $NON-NLS-1$
    k.setValue("config"); // $NON-NLS-1$

    // Flag values are ok to update
    k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_DEBUG);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.FLAGVALUE);
    assertEquals(k.getValue(), "false"); // $NON-NLS-1$
    k.setValue("true");

    k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_GCOV);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.FLAGVALUE);
    assertEquals(k.getValue(), "false"); // $NON-NLS-1$
    k.setValue("true");

    k = opts.get(AutotoolsOptionConstants.OPT_CFLAGS_GPROF);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.FLAGVALUE);
    assertEquals(k.getValue(), "false"); // $NON-NLS-1$
    k.setValue("true");

    // Check other options
    k = opts.get(AutotoolsOptionConstants.OPT_AUTOGENOPTS);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.MULTIARG);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("some opts");

    k = opts.get(AutotoolsOptionConstants.OPT_BINDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/bin");

    k = opts.get(AutotoolsOptionConstants.OPT_BUILD);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("linux");

    k = opts.get(AutotoolsOptionConstants.OPT_CACHE_FILE);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("config.status");

    k = opts.get(AutotoolsOptionConstants.OPT_DATADIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/data");

    k = opts.get(AutotoolsOptionConstants.OPT_ENABLE_MAINTAINER_MODE);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.BIN);
    assertEquals(k.getValue(), "false"); // $NON-NLS-1$
    k.setValue("true");

    k = opts.get(AutotoolsOptionConstants.OPT_EXEC_PREFIX);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/exec");

    k = opts.get(AutotoolsOptionConstants.OPT_HELP);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.BIN);
    assertEquals(k.getValue(), "false"); // $NON-NLS-1$
    k.setValue("true");

    k = opts.get(AutotoolsOptionConstants.OPT_HOST);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("linux");

    k = opts.get(AutotoolsOptionConstants.OPT_INCLUDEDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/include");

    k = opts.get(AutotoolsOptionConstants.OPT_INFODIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/info");

    k = opts.get(AutotoolsOptionConstants.OPT_LIBDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/lib");

    k = opts.get(AutotoolsOptionConstants.OPT_LIBEXECDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/libexec");

    k = opts.get(AutotoolsOptionConstants.OPT_LOCALSTATEDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/localstate");

    k = opts.get(AutotoolsOptionConstants.OPT_MANDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/man");

    k = opts.get(AutotoolsOptionConstants.OPT_NO_CREATE);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.BIN);
    assertEquals(k.getValue(), "false"); // $NON-NLS-1$
    k.setValue("true");

    k = opts.get(AutotoolsOptionConstants.OPT_OLDINCLUDEDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/oldinclude");

    k = opts.get(AutotoolsOptionConstants.OPT_PREFIX);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("prefix");

    k = opts.get(AutotoolsOptionConstants.OPT_PROGRAM_PREFIX);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("program_prefix");

    k = opts.get(AutotoolsOptionConstants.OPT_PROGRAM_SUFFIX);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("program_suffix");

    k = opts.get(AutotoolsOptionConstants.OPT_PROGRAM_TRANSFORM_NAME);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("program_transform_name");

    k = opts.get(AutotoolsOptionConstants.OPT_QUIET);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.BIN);
    assertEquals(k.getValue(), "false"); // $NON-NLS-1$
    k.setValue("true");

    k = opts.get(AutotoolsOptionConstants.OPT_SBINDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/sbin");

    k = opts.get(AutotoolsOptionConstants.OPT_SHAREDSTATEDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/sharedstate");

    k = opts.get(AutotoolsOptionConstants.OPT_SRCDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("src");

    k = opts.get(AutotoolsOptionConstants.OPT_SYSCONFDIR);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("/usr/sysconf");

    k = opts.get(AutotoolsOptionConstants.OPT_TARGET);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.STRING);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("target");

    k = opts.get(AutotoolsOptionConstants.OPT_USER);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.MULTIARG);
    assertEquals(k.getValue(), ""); // $NON-NLS-1$
    k.setValue("user opts");

    k = opts.get(AutotoolsOptionConstants.OPT_VERSION);
    assertTrue(k.canUpdate());
    assertEquals(k.getType(), IAutotoolsOption.BIN);
    assertEquals(k.getValue(), "false"); // $NON-NLS-1$
    k.setValue("true");

    // Verify last option changed has changed in our copy, but not
    // in the actual options
    assertEquals(k.getValue(), "true");
    Map<String, IAutotoolsOption> opts2 =
        AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId());
    IAutotoolsOption k2 = opts2.get(AutotoolsOptionConstants.OPT_VERSION);
    assertEquals(k2.getValue(), "false");

    // Now update the options we changed
    AutotoolsPlugin.getDefault().updateAutotoolCfgOptions(testProject, cfg.getId(), opts);
    opts2 = AutotoolsPlugin.getDefault().getAutotoolCfgOptions(testProject, cfg.getId());

    // Verify new option values
    k = opts2.get(AutotoolsOptionConstants.TOOL_AUTOGEN);
    assertEquals(k.getValue(), "autogen2.sh"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.TOOL_CONFIGURE);
    assertEquals(k.getValue(), "config"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_CFLAGS_DEBUG);
    assertEquals(k.getValue(), "true"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_CFLAGS_GCOV);
    assertEquals(k.getValue(), "true"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_CFLAGS_GPROF);
    assertEquals(k.getValue(), "true"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_AUTOGENOPTS);
    assertEquals(k.getValue(), "some opts"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_BINDIR);
    assertEquals(k.getValue(), "/usr/bin"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_BUILD);
    assertEquals(k.getValue(), "linux"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_CACHE_FILE);
    assertEquals(k.getValue(), "config.status"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_DATADIR);
    assertEquals(k.getValue(), "/usr/data"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_ENABLE_MAINTAINER_MODE);
    assertEquals(k.getValue(), "true"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_EXEC_PREFIX);
    assertEquals(k.getValue(), "/usr/exec"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_HELP);
    assertEquals(k.getValue(), "true"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_HOST);
    assertEquals(k.getValue(), "linux"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_INCLUDEDIR);
    assertEquals(k.getValue(), "/usr/include"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_INFODIR);
    assertEquals(k.getValue(), "/usr/info"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_LIBDIR);
    assertEquals(k.getValue(), "/usr/lib"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_LIBEXECDIR);
    assertEquals(k.getValue(), "/usr/libexec"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_LOCALSTATEDIR);
    assertEquals(k.getValue(), "/usr/localstate"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_MANDIR);
    assertEquals(k.getValue(), "/usr/man"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_NO_CREATE);
    assertEquals(k.getValue(), "true"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_OLDINCLUDEDIR);
    assertEquals(k.getValue(), "/usr/oldinclude"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_PREFIX);
    assertEquals(k.getValue(), "prefix"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_PROGRAM_PREFIX);
    assertEquals(k.getValue(), "program_prefix"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_PROGRAM_SUFFIX);
    assertEquals(k.getValue(), "program_suffix"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_PROGRAM_TRANSFORM_NAME);
    assertEquals(k.getValue(), "program_transform_name"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_QUIET);
    assertEquals(k.getValue(), "true"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_SBINDIR);
    assertEquals(k.getValue(), "/usr/sbin"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_SHAREDSTATEDIR);
    assertEquals(k.getValue(), "/usr/sharedstate"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_SRCDIR);
    assertEquals(k.getValue(), "src"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_SYSCONFDIR);
    assertEquals(k.getValue(), "/usr/sysconf"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_TARGET);
    assertEquals(k.getValue(), "target"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_USER);
    assertEquals(k.getValue(), "user opts"); // $NON-NLS-1$

    k = opts2.get(AutotoolsOptionConstants.OPT_VERSION);
    assertEquals(k.getValue(), "true"); // $NON-NLS-1$

    // Verify one updated option in the .autotools file for the project
    try {
      IPath fileLocation = testProject.getLocation().append(".autotools"); // $NON-NLS-1$
      File dirFile = fileLocation.toFile();
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      assertTrue(dirFile.exists());
      Document d = db.parse(dirFile);
      Element e = d.getDocumentElement();
      // Get the stored configuration data
      NodeList cfgs = e.getElementsByTagName("configuration"); // $NON-NLS-1$
      for (int x = 0; x < cfgs.getLength(); ++x) {
        Node n = cfgs.item(x);
        NodeList l = n.getChildNodes();
        for (int y = 0; y < l.getLength(); ++y) {
          Node child = l.item(y);
          if (child.getNodeName().equals("option")) { // $NON-NLS-1$
            NamedNodeMap optionAttrs = child.getAttributes();
            Node id = optionAttrs.getNamedItem("id"); // $NON-NLS-1$
            Node value = optionAttrs.getNamedItem("value"); // $NON-NLS-1$
            // Verify the bindir option is updated
            if (id.equals(AutotoolsOptionConstants.OPT_BINDIR))
              assertEquals(value, "/usr/bin"); // $NON-NLS-1$
          }
        }
      }
    } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
示例#28
0
 /**
  * Checks whether project is new CDT project
  *
  * @param p - project to check
  * @returns true if it's new-style project.
  */
 public static boolean isCDTPrj(IProject p) {
   ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, false);
   if (prjd == null) return false;
   ICConfigurationDescription[] cfgs = prjd.getConfigurations();
   return (cfgs != null && cfgs.length > 0);
 }
示例#29
0
  public void testEnablement_Bug250686() throws Exception {
    final String testName = getName();
    IProject project = ManagedBuildTestHelper.createProject(testName, PROJECT_TYPE);
    assertNotNull(project);

    IFolder folder = ManagedBuildTestHelper.createFolder(project, "Folder");
    assertNotNull(folder);

    IFile file = ManagedBuildTestHelper.createFile(project, "Folder/file.c");
    assertNotNull(file);

    ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project);
    prjDescription.getConfigurationByName(CFG_NAME);

    IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
    IConfiguration cfg = info.getManagedProject().getConfigurations()[0];
    assertNotNull(cfg);
    assertEquals(CFG_NAME, cfg.getName());

    {
      // Round 1. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 1. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 1. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from root folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Override the value of the option for the root folder
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      ITool[] tools = rootFolderInfo.getToolsBySuperClassId(TOOL_ID);
      assertEquals(1, tools.length);
      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      rootFolderInfo.setOption(tools[0], option, OPTION_VALUE_ROOT);
    }

    {
      // Round 2. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 2. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from root folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Override the value of the option for the subfolder
      IFolderInfo folderInfo = cfg.createFolderInfo(folder.getFullPath());
      assertNotNull(folderInfo);

      ITool[] tools = folderInfo.getToolsBySuperClassId(TOOL_ID);
      assertEquals(1, tools.length);

      IOption option = getOptionForFolder(folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());

      folderInfo.setOption(tools[0], option, OPTION_VALUE_FOLDER);
    }

    {
      // Round 3. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 3. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFolderInfo);

      // Option is taken from parent folder here
      IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Override the value of the option for the file
      IFileInfo fileInfo = cfg.createFileInfo(file.getFullPath());
      assertNotNull(fileInfo);

      ITool[] tools = fileInfo.getTools();
      assertEquals(1, tools.length);
      ITool tool = tools[0];
      assertNotNull(tool);

      IOption option = getOptionForFile(fileInfo, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());

      fileInfo.setOption(tool, option, OPTION_VALUE_FILE);
    }

    {
      // Round 4. Test root folder option
      IFolderInfo rootFolderInfo = cfg.getRootFolderInfo();
      assertNotNull(rootFolderInfo);

      IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_ROOT, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Test subfolder option
      IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false);
      assertNotNull(folderInfo);
      assertTrue(folderInfo instanceof IFolderInfo);

      IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FOLDER, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    {
      // Round 4. Test file option
      IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false);
      assertNotNull(fileInfo);
      assertTrue(fileInfo instanceof IFileInfo);

      IOption option = getOptionForFile((IFileInfo) fileInfo, OPTION_ID);
      assertNotNull(option);
      assertEquals(OPTION_VALUE_FILE, option.getValue());
      assertFalse(option.isExtensionElement());
    }

    ManagedBuildTestHelper.removeProject(testName);
  }
 private Map<String, IAConfiguration> getSavedConfigs(IProject project) {
   String projectName = project.getName();
   Map<String, IAConfiguration> list = configs.get(projectName);
   if (list == null) {
     try {
       IPath fileLocation = project.getLocation().append(CFG_FILE_NAME);
       File dirFile = fileLocation.toFile();
       Map<String, IAConfiguration> cfgList = new HashMap<>();
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
       DocumentBuilder db = dbf.newDocumentBuilder();
       if (dirFile.exists()) {
         Document d = db.parse(dirFile);
         Element e = d.getDocumentElement();
         // Get the stored configuration data
         NodeList cfgs = e.getElementsByTagName("configuration"); // $NON-NLS-1$
         for (int x = 0; x < cfgs.getLength(); ++x) {
           Node n = cfgs.item(x);
           NamedNodeMap attrs = n.getAttributes();
           // Originally we used the configuration name, but now we use
           // the ConfigurationDescription id which is unique.  Check for
           // id first, but fall back to name for older .autotools files.
           Node nameNode = attrs.getNamedItem("name"); // $NON-NLS-1$
           Node cfgIdNode = attrs.getNamedItem("id"); // $NON-NLS-1$
           String cfgId = null;
           if (cfgIdNode != null) cfgId = cfgIdNode.getNodeValue();
           else if (nameNode != null) {
             String cfgName = nameNode.getNodeValue();
             ICConfigurationDescription cfgd =
                 CoreModel.getDefault()
                     .getProjectDescription(project)
                     .getConfigurationByName(cfgName);
             if (cfgd != null) cfgId = cfgd.getId();
             else continue; // have to punt, this doesn't map to real cfg
           }
           IAConfiguration cfg = new AutotoolsConfiguration(cfgId);
           NodeList l = n.getChildNodes();
           for (int y = 0; y < l.getLength(); ++y) {
             Node child = l.item(y);
             if (child.getNodeName().equals("option")) { // $NON-NLS-1$
               NamedNodeMap optionAttrs = child.getAttributes();
               Node id = optionAttrs.getNamedItem("id"); // $NON-NLS-1$
               Node value = optionAttrs.getNamedItem("value"); // $NON-NLS-1$
               if (id != null && value != null)
                 cfg.setOption(id.getNodeValue(), value.getNodeValue());
             } else if (child.getNodeName().equals("flag")) { // $NON-NLS-1$
               // read in flag values
               NamedNodeMap optionAttrs = child.getAttributes();
               Node id = optionAttrs.getNamedItem("id"); // $NON-NLS-1$
               String idValue = id.getNodeValue();
               IConfigureOption opt = cfg.getOption(idValue);
               if (opt instanceof FlagConfigureOption) {
                 NodeList l2 = child.getChildNodes();
                 for (int z = 0; z < l2.getLength(); ++z) {
                   Node flagChild = l2.item(z);
                   if (flagChild.getNodeName().equals("flagvalue")) { // $NON-NLS-1$
                     NamedNodeMap optionAttrs2 = flagChild.getAttributes();
                     Node id2 = optionAttrs2.getNamedItem("id"); // $NON-NLS-1$
                     Node value = optionAttrs2.getNamedItem("value"); // $NON-NLS-1$
                     cfg.setOption(id2.getNodeValue(), value.getNodeValue());
                   }
                 }
               }
             }
           }
           cfg.setDirty(false);
           cfgList.put(cfg.getId(), cfg);
         }
         if (cfgList.size() > 0) {
           configs.put(projectName, cfgList);
           list = cfgList;
         }
       }
     } catch (ParserConfigurationException | SAXException | IOException e) {
       e.printStackTrace();
     }
   }
   return list;
 }