use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project linuxtools by eclipse.
the class RemoteProxyCMainTab method initializeProgramName.
/**
* Set the program name attributes on the working copy based on the
* ICElement.
* @param cElement The element to get data from.
* @param config The configuration to initialize
*/
protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
boolean renamed = false;
if (!(cElement instanceof IBinary)) {
cElement = cElement.getCProject();
}
if (cElement instanceof ICProject) {
IProject project = cElement.getCProject().getProject();
String name = project.getName();
ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
if (projDes != null) {
String buildConfigName = projDes.getActiveConfiguration().getName();
// Bug 234951
name = NLS.bind(LaunchMessages.CMainTab_Configuration_name, name, buildConfigName);
}
name = getLaunchConfigurationDialog().generateName(name);
config.rename(name);
renamed = true;
}
IBinary binary = null;
if (cElement instanceof ICProject) {
IBinary[] bins = getBinaryFiles((ICProject) cElement);
if (bins != null && bins.length == 1) {
binary = bins[0];
}
} else if (cElement instanceof IBinary) {
binary = (IBinary) cElement;
}
String projectDir = EMPTY_STRING;
IProject project = null;
try {
project = ConfigUtils.getProject(ConfigUtils.getProjectName(config));
} catch (CoreException e) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
}
if (project != null) {
try {
projectDir = RemoteProxyManager.getInstance().getRemoteProjectLocation(project);
} catch (CoreException e) {
setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
}
}
String path = EMPTY_STRING;
if (binary != null) {
path = binary.getResource().getProjectRelativePath().toOSString();
if (!renamed) {
String name = binary.getElementName();
int index = name.lastIndexOf('.');
if (index > 0) {
name = name.substring(0, index);
}
name = getLaunchConfigurationDialog().generateName(name);
config.rename(name);
renamed = true;
}
}
config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectDir + IPath.SEPARATOR + path);
if (!renamed) {
String name = getLaunchConfigurationDialog().generateName(cElement.getCProject().getElementName());
config.rename(name);
}
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class BoardDescriptor method createProject.
/*
* Method to create a project based on the board
*/
public IProject createProject(String projectName, URI projectURI, ArrayList<ConfigurationDescriptor> cfgNamesAndTCIds, CodeDescriptor codeDescription, CompileOptions compileOptions, IProgressMonitor monitor) throws Exception {
IProject projectHandle;
projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(Common.MakeNameCompileSafe(projectName));
// try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IProjectDescription desc = workspace.newProjectDescription(projectHandle.getName());
desc.setLocationURI(projectURI);
projectHandle.create(desc, monitor);
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
projectHandle.open(IResource.BACKGROUND_REFRESH, monitor);
// Creates the .cproject file with the configurations
ICProjectDescription prjCDesc = ShouldHaveBeenInCDT.setCProjectDescription(projectHandle, cfgNamesAndTCIds, true, monitor);
// Add the C C++ AVR and other needed Natures to the project
Helpers.addTheNatures(desc);
// Add the Arduino folder
Helpers.createNewFolder(projectHandle, Const.ARDUINO_CODE_FOLDER_NAME, null);
for (ConfigurationDescriptor curConfig : cfgNamesAndTCIds) {
ICConfigurationDescription configurationDescription = prjCDesc.getConfigurationByName(curConfig.configName);
compileOptions.save(configurationDescription);
save(configurationDescription);
}
// Set the path variables
// ArduinoHelpers.setProjectPathVariables(prjCDesc.getActiveConfiguration());
// Intermediately save or the adding code will fail
// Release is the active config (as that is the "IDE" Arduino
// type....)
ICConfigurationDescription defaultConfigDescription = prjCDesc.getConfigurationByName(cfgNamesAndTCIds.get(0).configName);
ICResourceDescription cfgd = defaultConfigDescription.getResourceDescription(new Path(new String()), true);
ICExclusionPatternPathEntry[] entries = cfgd.getConfiguration().getSourceEntries();
if (entries.length == 1) {
Path[] exclusionPath = new Path[6];
exclusionPath[0] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/?xamples/**");
exclusionPath[1] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/?xtras/**");
exclusionPath[2] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/test*/**");
exclusionPath[3] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/third-party/**");
exclusionPath[4] = new Path(LIBRARY_PATH_SUFFIX + "/**/._*");
exclusionPath[5] = new Path(LIBRARY_PATH_SUFFIX + "/?*/utility/*/*");
ICExclusionPatternPathEntry newSourceEntry = new CSourceEntry(entries[0].getFullPath(), exclusionPath, ICSettingEntry.VALUE_WORKSPACE_PATH);
ICSourceEntry[] out = null;
out = new ICSourceEntry[1];
out[0] = (ICSourceEntry) newSourceEntry;
try {
cfgd.getConfiguration().setSourceEntries(out);
} catch (CoreException e) {
// ignore
}
} else {
// this should not happen
}
Set<String> librariesToInstall = codeDescription.createFiles(projectHandle, monitor);
Libraries.addLibrariesToProject(projectHandle, defaultConfigDescription, librariesToInstall);
prjCDesc.setActiveConfiguration(defaultConfigDescription);
prjCDesc.setCdtProjectCreated();
CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(projectHandle, prjCDesc, true, null);
projectHandle.setDescription(desc, new NullProgressMonitor());
projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
monitor.done();
return projectHandle;
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class Libraries method addLibrariesToProject.
public static void addLibrariesToProject(IProject project, Set<String> selectedLibraries) {
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription projectDescription = mngr.getProjectDescription(project, true);
ICConfigurationDescription configurationDescription = projectDescription.getActiveConfiguration();
addLibrariesToProject(project, configurationDescription, selectedLibraries);
try {
mngr.setProjectDescription(project, projectDescription, true, null);
} catch (CoreException e) {
e.printStackTrace();
}
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class Common method setBuildEnvironmentVariable.
public static void setBuildEnvironmentVariable(IProject project, String envName, String value) {
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
setBuildEnvironmentVariable(prjDesc.getDefaultSettingConfiguration(), envName, value);
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class ExplorerLabelDecorator method decorateText.
@Override
public String decorateText(String text, Object element) {
IProject proj = (IProject) element;
if (proj.isOpen()) {
if (Sketch.isSketch(proj)) {
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(proj);
if (prjDesc == null) {
return new String();
}
ICConfigurationDescription configurationDescription = prjDesc.getActiveConfiguration();
BoardDescriptor boardDescriptor = BoardDescriptor.makeBoardDescriptor(configurationDescription);
String boardName = boardDescriptor.getBoardName();
String portName = boardDescriptor.getUploadPort();
if (portName.isEmpty()) {
// $NON-NLS-1$
portName = "no port";
}
if (boardName.isEmpty()) {
// $NON-NLS-1$
boardName = "no Board";
}
return text + ' ' + boardName + ' ' + ':' + portName;
}
}
return null;
}
Aggregations