Bug 336377 - [API] Adding CDT Nature and Managed Build to an existing project requires using of not public API-s of CDT
Summary: [API] Adding CDT Nature and Managed Build to an existing project requires usi...
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build-managed (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 318063 320296
  Show dependency tree
 
Reported: 2011-02-04 12:17 EST by Alexandre Rusev CLA
Modified: 2020-09-04 15:20 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandre Rusev CLA 2011-02-04 12:17:24 EST
Build Identifier: Build id: M20100211-1343

Adding CDT Nature and Managed Build to an existing project requires using of not public API-s of CDT

The following packages need to be imported:
org.eclipse.cdt.managedbuilder.internal.core.Configuration
org.eclipse.cdt.managedbuilder.internal.core.ManagedProject

The following quotation explains modetails:

http://cdt-devel-faq.wikidot.com/#toc25


If you have an existing project type and want to add CDT capabilities & features to it, you can try the code below in your plug-in:

CProjectNature.addCNature(fProject, mon);
ICProjectDescriptionManager mgr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mgr.getProjectDescription(fProject, true);

if (des != null)
        return; // C project description already exists

des = mgr.createProjectDescription(fProject, true);

ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(fProject);
IProjectType projType =
         ManagedBuildManager.getExtensionProjectType("my.project.type"); // or get projectType from UI
IToolChain toolChain =
         ManagedBuildManager.getExtensionToolChain("my.toolchain"); // or get toolChain from UI

ManagedProject mProj = new ManagedProject(fProject, projType);
info.setManagedProject(mProj);

IConfiguration[] configs = ManagedBuildManager.getExtensionConfigurations(toolChain, projType);

for (IConfiguration icf : configs) {
    if (!(icf instanceof Configuration)) {
        continue;
    }
    Configuration cf = (Configuration) icf;

    String id = ManagedBuildManager.calculateChildId(cf.getId(), null);
    Configuration config = new Configuration(mProj, cf, id, false, true);

    ICConfigurationDescription cfgDes =
    des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID,
                                         config.getConfigurationData());
    config.setConfigurationDescription(cfgDes);
    config.exportArtifactInfo();

    IBuilder bld = config.getEditableBuilder();
    if (bld != null) { bld.setManagedBuildOn(true); }

    config.setName(toolChain.getName());
    config.setArtifactName(fProject.getName());

}

mgr.setProjectDescription(fProject, des);

Of course, you have to replace "my.project.type" and "my.toolchain" with the appropriate CDT project type and toolchains, respectively.

There's still one caveat, though. You will notice the code directly instantiates an instance of Configuration which is inside an internal package of CDT. Unfortunately, as of now there's no "valid" way to create it with the same parameters as we did. We will have to request an addition to the API to support this.


Reproducible: Always
Comment 1 Doug Schaefer CLA 2011-02-04 13:04:28 EST
Actually, you can checkout what I'm doing here:

   https://github.com/dschaefer/adt-cdt
Comment 2 Anna Dushistova CLA 2011-02-07 03:48:45 EST
Hey Doug, how is that related to the issue described?
Maybe you can point to more exact location where to look for the answer?
Thanks!

(In reply to comment #1)
> Actually, you can checkout what I'm doing here:
> 
>    https://github.com/dschaefer/adt-cdt
Comment 3 Doug Schaefer CLA 2011-02-07 09:07:15 EST
I was able to do as suggested by using the STDWizardHandler which hides all the internals you are trying to use. You can see it in the NDKWizardHander in my project on github.