Skip to content

Conversation

jantje
Copy link
Member

@jantje jantje commented Jul 7, 2020

No description provided.

/*
* Method to create a project based on the board
*/
public IProject createProject(String projectName, URI projectURI,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the old create project that uses the "shouldhaveBeeninCDT.java" that has been deleted.

Comment on lines +521 to +607
public IProject createProject(String projectName, URI projectURI, CodeDescriptor codeDescription,
CompileOptions compileOptions, IProgressMonitor monitor) throws Exception {

String realProjectName = Common.MakeNameCompileSafe(projectName);
// IProject newProjectHandle = ManagedBuildTestHelper.createProject(realProjectName, projectURI,
// "io.sloeber.core.sketch");

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final IProject newProjectHandle = root.getProject(realProjectName);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();

IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {

try {
// Create the base project
IWorkspaceDescription workspaceDesc = workspace.getDescription();
workspaceDesc.setAutoBuilding(false);
workspace.setDescription(workspaceDesc);

IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
if (projectURI != null) {
description.setLocationURI(projectURI);
}

CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(),
ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
// Add the managed build nature and builder
addManagedBuildNature(newProjectHandle);

// Find the base project type definition
IProjectType projType = ManagedBuildManager.getProjectType("io.sloeber.core.sketch");

// Create the managed-project (.cdtbuild) for our project that builds an
// executable.
IManagedProject newProject = null;
newProject = ManagedBuildManager.createManagedProject(newProjectHandle, projType);
ManagedBuildManager.setNewProjectVersion(newProjectHandle);
// Copy over the configs
IConfiguration defaultConfig = null;
IConfiguration[] configs = projType.getConfigurations();
for (int i = 0; i < configs.length; ++i) {
// Make the first configuration the default
if (i == 0) {
defaultConfig = newProject.createConfiguration(configs[i], projType.getId() + "." + i); //$NON-NLS-1$
} else {
newProject.createConfiguration(configs[i], projType.getId() + "." + i); //$NON-NLS-1$
}
}
ManagedBuildManager.setDefaultConfiguration(newProjectHandle, defaultConfig);

IConfiguration cfgs[] = newProject.getConfigurations();
for (int i = 0; i < cfgs.length; i++) {
cfgs[i].setArtifactName(newProject.getDefaultArtifactName());
}
codeDescription.createFiles(newProjectHandle, new NullProgressMonitor());
ManagedCProjectNature.addNature(newProjectHandle, "org.eclipse.cdt.core.ccnature", monitor);
ManagedCProjectNature.addNature(newProjectHandle, Const.ARDUINO_NATURE_ID, monitor);

CCorePlugin cCorePlugin = CCorePlugin.getDefault();
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(newProjectHandle);
for (ICConfigurationDescription curConfig : prjCDesc.getConfigurations()) {
compileOptions.save(curConfig);
save(curConfig);
}
cCorePlugin.setProjectDescription(newProjectHandle, prjCDesc, true, null);

ManagedBuildManager.getBuildInfo(newProjectHandle).setValid(true);
} catch (Exception e) {

return;
}

}
};

try {
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e2) {

}

monitor.done();

return newProjectHandle;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is the new way that still kicks in the indexer to early

@jantje jantje deleted the #1163_create_project_the_cdt_way branch October 13, 2020 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant