以编程方式创建的C项目

时间:2016-11-07 08:05:53

标签: java eclipse eclipse-plugin eclipse-cdt

我正在使用CDT以编程方式创建一个C项目:

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();

    String projectName = projectNames[indices[i]];

    IProject newProjectHandle = root.getProject(projectName.replace("Examples_", ""));

    IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
    IProject project = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, new NullProgressMonitor());

    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    ICProjectDescription des = mngr.createProjectDescription(project, false);
    ManagedProject mProj = new ManagedProject(des);


    Configuration cfg = new Configuration(mProj, null, projectName + ".id", projectName);
    cfg.setManagedBuildOn(false);
    IBuilder bld = cfg.getEditableBuilder();

    bld.setManagedBuildOn(false);
    bld.setAutoBuildEnable(false);


    CConfigurationData data = cfg.getConfigurationData();
    des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);


    mngr.setProjectDescription(project, des);

这与从C向导创建makefile项目完全一样。

我现在想要的是以编程方式从项目属性中取消CDT构建器。

enter image description here

通过在项目创建代码中添加一行或两行,有没有简单的方法呢?

1 个答案:

答案 0 :(得分:0)

确定设法更改代码,以便在没有构建器的情况下创建C项目:

            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IWorkspaceRoot root = workspace.getRoot();

            String projectName = projectNames[indices[i]];

            IProject newProjectHandle = root.getProject(projectName.replace("Examples_", ""));

            newProjectHandle.create(new NullProgressMonitor());
            IProjectDescription description = workspace
                    .newProjectDescription(newProjectHandle.getName());

            newProjectHandle = CCorePlugin.getDefault().createCProject(description,
                    newProjectHandle, new NullProgressMonitor(),
                    ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
            IndexerPreferences.set(newProjectHandle,
                    IndexerPreferences.KEY_INCLUDE_HEURISTICS, "true");