Hello.
I have been trying to create CDT Project programmatically with multiple files and trying to get translation unit out of it. However, I always get an empty list in return, while extracting the translation units out of the project.Can someone guide me, what is the correct way of creating a CDT project with multiple files in it.
Currently I am using the following code which is not giving me correct results:
private ICProject createCDTProjectFromFiles(final File[] files)
throws OperationCanceledException, CoreException, FileNotFoundException {
final IProject proj = createCDTProject("Test Project 10");
mCdtProject = proj;
mLogger.info("Created temporary CDT project at " + getFullPath(mCdtProject));
final IFolder sourceFolder = mCdtProject.getFolder("src");
sourceFolder.create(true, true, NULL_MONITOR);
final ICSourceEntry entrySrc = new CSourceEntry(sourceFolder, null, ICSettingEntry.RESOLVED);
// CDataUtil.createEntry(CDataUtil., String name, String value, IPath[] exclusionPatterns, int flags)
// CDataUtil
// entrySrc.
for (final File file : files) {
createCopyOfFileInProject(mCdtProject, sourceFolder, file);
}
final CoreModel model = CoreModel.getDefault();
final ICProject icdtProject = model.create(mCdtProject);
return icdtProject;
}
private static IProject createCDTProject(final String projectName)
throws OperationCanceledException, CoreException {
final CCorePlugin cdtCorePlugin = CCorePlugin.getDefault();
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot root = workspace.getRoot();
IProject project = root.getProject(projectName);
IndexerPreferences.set(project, IndexerPreferences.KEY_INDEX_ALL_FILES, IPDOMManager.ID_FAST_INDEXER);
final IProjectDescription prjDescription = workspace.newProjectDescription(projectName);
project = cdtCorePlugin.createCDTProject(prjDescription, project, NULL_MONITOR);
waitForProjectRefreshToFinish();
// Assert.assertNotNull(project);
project.open(null);
// Assert.assertTrue(project.isOpen());
return project;
}
Thanks.
Regards,
Muhammad Hamiz Ahmed