Taani
Taani

Reputation: 137

Eclipse - CDT programmatically added include paths does not appear

I am developing an eclipse-java plugin to programmatically add include paths to a project. The part of code which I used was following.

String includePath = null;
ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project, true);
ICConfigurationDescription configDecriptions[] = projectDescription.getConfigurations();
for (ICConfigurationDescription configDescription : configDecriptions) {
ICFolderDescription projectRoot = configDescription.getRootFolderDescription();
ICLanguageSetting[] settings = projectRoot.getLanguageSettings();
for (ICLanguageSetting setting : settings) {
    if (!"org.eclipse.cdt.core.gcc".equals(setting.getLanguageId())) {
    continue;
    }
    List<ICLanguageSettingEntry> includes = new ArrayList<ICLanguageSettingEntry>();
        includes.addAll(setting.getSettingEntriesList(ICSettingEntry.INCLUDE_PATH));
    for (int i = 0; i < tableViewer.getTable().getItemCount(); i++) {
        includePath = tableViewer.getTable().getItem(i).getText();
        includes.add(new CIncludePathEntry(includePath, ICSettingEntry.LOCAL));
    }
    setting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, includes);
    }
}
CoreModel.getDefault().setProjectDescription(project, projectDescription);

When I print the values returned from ICLanguageSetting.getSettingEntries(), the include paths are succeessfully added. But they are not reflected in the properties->C/C++General->Paths&Symbols dialog or in Project Explorer view.

Am I missing any update() or refresh() ?

Upvotes: 3

Views: 1121

Answers (1)

Erika Redmark
Erika Redmark

Reputation: 489

I know this has been 3 months so hopefully it's still relevant.

My code looks almost identical to yours but the include paths are shown in properties->C/C++General->Paths&Symbols and work. So I went through each line and there is only one big difference I can see:

For constructing a new CIncludePathEntry, the first argument I pass in is an IFolder, not a String, so I am using a different constructor. I am not sure how the rest of your program is structured, but perhaps you can call IProject.getFolder(String) and work with that instead.

Upvotes: 1

Related Questions