IWorkspaceRoot root = workspace.getRoot();
IProject newProjectHandle = root.getProject(newComponentWizardPage.getProjectName());
IProject newProject = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, newNullProgressMonitor());
ManagedCProjectNature.addNature(newProject, "org.eclipse.cdt.core.ccnature", null);
ICProjectDescriptionManager mgr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription des = mgr.getProjectDescription(newProject, true);
des = mgr.createProjectDescription(newProject, true);
IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(newProject);
IProjectType projType = ManagedBuildManager.getExtensionProjectType("cdt.managedbuild.target.gnu.exe");
IToolChain toolChain = ManagedBuildManager.getExtensionToolChain("cdt.managedbuild.toolchain.gnu.exe.release");
IManagedProject mProj = new ManagedProject(newProject,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((ManagedProject) mProj, cf, id, false, true);
ICConfigurationDescription cfgDes = null;
try {
cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID,config.getConfigurationData());
} catch (WriteAccessException e1) {
e1.printStackTrace();
} catch (CoreException e1) {
e1.printStackTrace();
}
config.setConfigurationDescription(cfgDes);
config.exportArtifactInfo();
IBuilder bld = config.getEditableBuilder();
if (bld != null) {
try {
bld.setBuildPath("${workspace_loc:/" + newComponentWizardPage.getProjectName()
+ "/" + generatorParameters.getSrcDirectory()+ "}");
bld.setManagedBuildOn(false);
} catch (CoreException e) {
e.printStackTrace();
}
}
config.setName(toolChain.getName());
config.setArtifactName(newProject.getName());
}
mgr.setProjectDescription(newProject, des);
참고자료 : http://cdt-devel-faq.wikidot.com/#toc25
PS. 참고적으로 저는 이 코드가 때문에 몇 일 동안 삽질을 했습니다. 이유없이 계속 새로운 인스턴스가 생성되지 않았던 것입니다. 결국 원인을 찾아내 보니 id를 잘 못 넣었던 것입니다. 저번에도 id 때문에 몇 일 삽질한 적이 있었는데 이번에도 역시 id때문에 고생을 하게 되었습니다.
위의 그림에서 처럼 projectType id를 입력해야 하는데 propertyType id를 넣었으니.... 그러고도 되기를 원했으니...





최근 덧글