use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project usbdm-eclipse-plugins by podonoghue.
the class ProjectUtilities method createNewStyleProjectFolder.
/**
* @param monitor
* @param projectHandle
* @param folder
* @throws CoreException
* @throws WriteAccessException
*/
private static void createNewStyleProjectFolder(IProgressMonitor monitor, IProject projectHandle, IFolder folder) throws CoreException, WriteAccessException {
ICSourceEntry newEntry = new CSourceEntry(folder, null, 0);
ICProjectDescription description = CCorePlugin.getDefault().getProjectDescription(projectHandle);
ICConfigurationDescription[] configs = description.getConfigurations();
for (int i = 0; i < configs.length; i++) {
ICConfigurationDescription config = configs[i];
ICSourceEntry[] entries = config.getSourceEntries();
Set<ICSourceEntry> set = new HashSet<ICSourceEntry>();
for (int j = 0; j < entries.length; j++) {
if (new Path(entries[j].getValue()).segmentCount() == 1)
continue;
set.add(entries[j]);
}
set.add(newEntry);
config.setSourceEntries(set.toArray(new ICSourceEntry[set.size()]));
}
CCorePlugin.getDefault().setProjectDescription(projectHandle, description, false, monitor);
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project m2e-nar by maven-nar.
the class CProjectConfigurator method getCdtProject.
private ICProjectDescription getCdtProject(IProject project, IToolChain tc, String artefactType, IProgressMonitor monitor) throws CoreException {
try {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
if (!project.hasNature(CCProjectNature.CC_NATURE_ID)) {
MavenNarPlugin.getDefault().log("Configuring project with " + tc.getUniqueRealName() + " tool chain");
// Add the C++ Nature
CCorePlugin.getDefault().convertProjectToNewCC(project, ManagedBuildManager.CFG_DATA_PROVIDER_ID, monitor);
ICProjectDescription des = mngr.createProjectDescription(project, false, false);
IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
List<IConfiguration> cfgs = getCfgs(tc, artefactType);
if (cfgs.isEmpty()) {
throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot find any configurations"));
}
IConfiguration cf = cfgs.get(0);
IManagedProject mProj = ManagedBuildManager.createManagedProject(project, cf.getProjectType());
info.setManagedProject(mProj);
return des;
} else {
ICProjectDescription des = mngr.getProjectDescription(project, true);
return des;
}
} catch (BuildException e) {
throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot create CDT managed project", e));
}
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class Sketch method addCodeFolder.
/**
* Adds a folder to the project and adds the folder to the linked folders if
* needed Stores the projectDescription if it has changed
*
* @param project
* the project to add the folder to
* @param path
* the path that needs adding to the project
*
* @throws CoreException
*/
public static void addCodeFolder(IProject project, Path path) throws CoreException {
boolean projDescNeedsSaving = false;
CoreModel coreModel = CoreModel.getDefault();
ICProjectDescription projectDescription = coreModel.getProjectDescription(project);
List<IPath> includeFolders = Helpers.addCodeFolder(project, path, path.lastSegment(), false);
for (ICConfigurationDescription curConfig : projectDescription.getConfigurations()) {
if (Helpers.addIncludeFolder(curConfig, includeFolders, true)) {
projDescNeedsSaving = true;
}
}
if (projDescNeedsSaving) {
coreModel.getProjectDescriptionManager().setProjectDescription(project, projectDescription, true, null);
}
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class SloeberProject method convertToArduinoProject.
/**
* convenient method to create project
*
* @param proj1Name
* @param object
* @param proj1BoardDesc
* @param codeDesc
* @param proj1CompileDesc
* @param otherDesc
* @param nullProgressMonitor
* @return
*/
public static void convertToArduinoProject(IProject project, IProgressMonitor monitor) {
if (project == null) {
return;
}
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
ICoreRunnable runnable = new ICoreRunnable() {
@Override
public void run(IProgressMonitor internalMonitor) throws CoreException {
IndexerController.doNotIndex(project);
try {
// create a sloeber project
SloeberProject sloeberProject = new SloeberProject(project);
if (!sloeberProject.readConfigFromFiles()) {
String RELEASE = "Release";
sloeberProject.setBoardDescription(RELEASE, new BoardDescription(), false);
sloeberProject.setCompileDescription(RELEASE, new CompileDescription());
sloeberProject.setOtherDescription(RELEASE, new OtherDescription());
// we failed to read from disk so we set opourselfves some values
// faking the stuf is in memory
}
String configName = sloeberProject.myBoardDescriptions.keySet().iterator().next();
BoardDescription boardDescriptor = sloeberProject.getBoardDescription(configName, true);
// Add the arduino code folders
List<IPath> addToIncludePath = Helpers.addArduinoCodeToProject(project, boardDescriptor);
// make the eclipse project a cdt project
CCorePlugin.getDefault().createCProject(null, project, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
// add the required natures
ManagedCProjectNature.addManagedNature(project, internalMonitor);
ManagedCProjectNature.addManagedBuilder(project, internalMonitor);
// $NON-NLS-1$
ManagedCProjectNature.addNature(project, "org.eclipse.cdt.core.ccnature", internalMonitor);
ManagedCProjectNature.addNature(project, Const.ARDUINO_NATURE_ID, internalMonitor);
// make the cdt project a managed build project
// $NON-NLS-1$
IProjectType sloeberProjType = ManagedBuildManager.getProjectType("io.sloeber.core.sketch");
ManagedBuildManager.createBuildInfo(project);
IManagedProject newProject = ManagedBuildManager.createManagedProject(project, sloeberProjType);
ManagedBuildManager.setNewProjectVersion(project);
// Copy over the Sloeber configs
IConfiguration defaultConfig = null;
IConfiguration[] configs = sloeberProjType.getConfigurations();
for (int i = 0; i < configs.length; ++i) {
IConfiguration curConfig = newProject.createConfiguration(configs[i], // $NON-NLS-1$
sloeberProjType.getId() + "." + i);
curConfig.setArtifactName(newProject.getDefaultArtifactName());
// Make the first configuration the default
if (i == 0) {
defaultConfig = curConfig;
}
}
ManagedBuildManager.setDefaultConfiguration(project, defaultConfig);
Map<String, String> configs2 = new HashMap<>();
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(project);
ICConfigurationDescription activeConfig = prjCDesc.getActiveConfiguration();
for (String curConfigName : sloeberProject.myBoardDescriptions.keySet()) {
ICConfigurationDescription curConfigDesc = prjCDesc.getConfigurationByName(curConfigName);
if (curConfigDesc == null) {
String id = CDataUtil.genId(null);
curConfigDesc = prjCDesc.createConfiguration(id, curConfigName, activeConfig);
}
Helpers.addIncludeFolder(curConfigDesc, addToIncludePath, true);
String curConfigKey = getConfigKey(curConfigDesc);
sloeberProject.myEnvironmentVariables.put(curConfigKey, sloeberProject.getEnvVars(curConfigKey));
configs2.put(curConfigName, curConfigDesc.getId());
}
sloeberProject.myIsInMemory = true;
sloeberProject.createSloeberConfigFiles(prjCDesc);
SubMonitor refreshMonitor = SubMonitor.convert(internalMonitor, 3);
project.refreshLocal(IResource.DEPTH_INFINITE, refreshMonitor);
cCorePlugin.setProjectDescription(project, prjCDesc, true, null);
} catch (Exception e) {
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Project conversion failed: ", // $NON-NLS-1$
e));
}
IndexerController.index(project);
}
};
try {
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
} catch (Exception e) {
// $NON-NLS-1$
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Project conversion failed: ", e));
}
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class SloeberProject method getDecoratedText.
/**
* get the text for the decorator
*
* @param text
* @return
*/
public String getDecoratedText(String text) {
if (!isInMemory()) {
configure();
}
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(myProject);
if (prjDesc != null) {
ICConfigurationDescription confDesc = prjDesc.getActiveConfiguration();
if (confDesc != null) {
// do not use getBoardDescriptor below as this will cause a infinite loop at
// project creation
BoardDescription boardDescriptor = myBoardDescriptions.get(getConfigKey(confDesc));
if (boardDescriptor == null) {
// $NON-NLS-1$
return text + " Project not configured";
}
String boardName = boardDescriptor.getBoardName();
String portName = boardDescriptor.getActualUploadPort();
if (portName.isEmpty()) {
portName = Messages.decorator_no_port;
}
if (boardName.isEmpty()) {
boardName = Messages.decorator_no_platform;
}
return text + ' ' + boardName + ' ' + ':' + portName;
}
}
return text;
}
Aggregations