use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class Sketch method getAllAvailableLibraries.
public static Map<String, IPath> getAllAvailableLibraries(IProject project) {
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
if (prjDesc != null) {
return Libraries.getAllInstalledLibraries(prjDesc.getActiveConfiguration());
}
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, "Is the selected project a C/Cpp project? " + project.getName(), // $NON-NLS-1$
null));
return new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class UploadSketchWrapper method internalUpload.
public void internalUpload(IProject project, String configName) {
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project);
ICConfigurationDescription confDesc = prjDesc.getConfigurationByName(configName);
BoardDescriptor boardDescriptor = BoardDescriptor.makeBoardDescriptor(confDesc);
String UpLoadTool = boardDescriptor.getActualUploadTool(confDesc);
String MComPort = boardDescriptor.getUploadPort();
String host = boardDescriptor.getHost();
String uploadClass = Common.getBuildEnvironmentVariable(confDesc, Common.get_ENV_KEY_TOOL(Const.UPLOAD_CLASS), new String());
this.myConsole = Helpers.findConsole(Messages.Upload_console);
this.myConsole.clearConsole();
this.myConsole.activate();
this.myHighLevelConsoleStream = this.myConsole.newMessageStream();
this.myOutconsoleStream = this.myConsole.newMessageStream();
this.myErrconsoleStream = this.myConsole.newMessageStream();
this.myHighLevelConsoleStream.setColor(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK));
this.myOutconsoleStream.setColor(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN));
this.myErrconsoleStream.setColor(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_RED));
this.myHighLevelConsoleStream.println(Messages.Upload_starting);
IRealUpload realUploader = null;
String uploadJobName = null;
if (host != null) {
if (Const.UPLOAD_CLASS_DEFAULT.equals(uploadClass)) {
this.myHighLevelConsoleStream.println(Messages.Upload_arduino);
realUploader = new arduinoUploader(project, configName, UpLoadTool, this.myConsole);
uploadJobName = UpLoadTool;
} else {
this.myHighLevelConsoleStream.println(Messages.Upload_ssh);
realUploader = new SSHUpload(project, UpLoadTool, this.myHighLevelConsoleStream, this.myOutconsoleStream, this.myErrconsoleStream, host);
uploadJobName = UPLOAD_SSH;
}
} else if (UpLoadTool.equalsIgnoreCase(UPLOAD_TOOL_TEENSY)) {
this.myHighLevelConsoleStream.println(Messages.Upload_generic);
realUploader = new GenericLocalUploader(UpLoadTool, project, configName, this.myConsole, this.myErrconsoleStream, this.myOutconsoleStream);
uploadJobName = UpLoadTool;
} else {
this.myHighLevelConsoleStream.println(Messages.Upload_arduino);
realUploader = new arduinoUploader(project, configName, UpLoadTool, this.myConsole);
uploadJobName = UpLoadTool;
}
Job uploadjob = new UploadJobWrapper(uploadJobName, project, configName, realUploader, MComPort, boardDescriptor);
uploadjob.setRule(null);
uploadjob.setPriority(Job.LONG);
uploadjob.setUser(true);
uploadjob.schedule();
Job job = new Job(Messages.Upload_PluginStartInitiator) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
// $NON-NLS-1$
String uploadflag = "FuStatus";
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't', '/', 'e', 'c', 'l', 'i', 'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a', 'd', '/', 'u', 'p', 'l', 'o', 'a', 'd', 'S', 't', 'a', 'r', 't', '.', 'h', 't', 'm', 'l', '?', 'u', '=' };
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
int curFsiStatus = myScope.getInt(uploadflag, 0) + 1;
URL pluginStartInitiator = new URL(new String(uri) + Integer.toString(curFsiStatus));
pluginStartInitiator.getContent();
myScope.putInt(uploadflag, curFsiStatus);
} catch (Exception e) {
e.printStackTrace();
}
return Status.OK_STATUS;
}
};
job.setPriority(Job.DECORATE);
job.schedule();
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project arduino-eclipse-plugin by Sloeber.
the class arduinoUploader method uploadUsingPreferences.
@Override
public boolean uploadUsingPreferences(IFile hexFile, BoardDescriptor inBoardDescriptor, IProgressMonitor monitor) {
String MComPort = new String();
String boardName = new String();
boolean needsPassword = false;
boolean needsUpdatedConfig = false;
BoardDescriptor boardDescriptor = BoardDescriptor.makeBoardDescriptor(inBoardDescriptor);
IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager();
IContributedEnvironment contribEnv = envManager.getContributedEnvironment();
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(this.myProject);
ICConfigurationDescription configurationDescription = prjDesc.getConfigurationByName(this.mycConf);
try {
needsPassword = envManager.getVariable(Const.ENV_KEY_NETWORK_AUTH, configurationDescription, true).getValue().equalsIgnoreCase(Const.TRUE);
} catch (Exception e) {
// ignore all errors
}
if (!boardDescriptor.usesProgrammer()) {
String NewSerialPort = ArduinoSerial.makeArduinoUploadready(this.myConsole.newMessageStream(), this.myProject, this.mycConf, boardDescriptor);
if (!boardDescriptor.getUploadPort().equals(NewSerialPort)) {
boardDescriptor.setUploadPort(NewSerialPort);
needsUpdatedConfig = true;
}
}
// for web authorized upload
if (needsPassword) {
setEnvironmentvarsForAutorizedUpload(contribEnv, configurationDescription, MComPort);
}
if (needsUpdatedConfig) {
try {
boardDescriptor.saveConfiguration(configurationDescription, null);
} catch (Exception e) {
Common.log(new // $NON-NLS-1$
Status(// $NON-NLS-1$
IStatus.ERROR, // $NON-NLS-1$
Const.CORE_PLUGIN_ID, // $NON-NLS-1$
"Failed to save configuration before upload", e));
return false;
}
}
String command = boardDescriptor.getUploadCommand(configurationDescription);
if (command == null) {
// $NON-NLS-1$
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to get the Upload recipe "));
return false;
}
try {
GenericLocalUploader.RunConsoledCommand(this.myConsole, command, monitor);
} catch (IOException e1) {
// $NON-NLS-1$
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Failed to run the Upload recipe ", e1));
return false;
}
if (boardName.startsWith("Arduino Due ")) {
// $NON-NLS-1$
ArduinoSerial.reset_Arduino_by_baud_rate(MComPort, 115200, 100);
}
return true;
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project usbdm-eclipse-plugins by podonoghue.
the class CDTProjectManager method createUSBDMProject.
/**
* Create USBDM CDT project
*
* @param paramMap Parameters for project (from Wizard dialogue)
* @param monitor Progress monitor
*
* @return Created project
*
* @throws Exception
*/
public IProject createUSBDMProject(Map<String, String> paramMap, IProgressMonitor progressMonitor) throws Exception {
SubMonitor monitor = SubMonitor.convert(progressMonitor);
// Create model project and accompanied descriptions
IProject project;
try {
monitor.beginTask("Create configuration", 100);
String projectName = MacroSubstitute.substitute(paramMap.get(UsbdmConstants.PROJECT_NAME_KEY), paramMap);
String directoryPath = MacroSubstitute.substitute(paramMap.get(UsbdmConstants.PROJECT_HOME_PATH_KEY), paramMap);
String projectType = MacroSubstitute.substitute(paramMap.get(UsbdmConstants.PROJECT_OUTPUT_TYPE_KEY), paramMap);
InterfaceType interfaceType = InterfaceType.valueOf(paramMap.get(UsbdmConstants.INTERFACE_TYPE_KEY));
boolean hasCCNature = Boolean.valueOf(paramMap.get(UsbdmConstants.HAS_CC_NATURE_KEY));
String artifactName = MacroSubstitute.substitute(paramMap.get(UsbdmConstants.PROJECT_ARTIFACT_KEY), paramMap);
if ((artifactName == null) || (artifactName.length() == 0)) {
artifactName = "${ProjName}";
}
project = createProject(projectName, directoryPath, hasCCNature, monitor.newChild(70));
CoreModel coreModel = CoreModel.getDefault();
// Create project description
ICProjectDescription projectDescription = coreModel.createProjectDescription(project, false);
Assert.isNotNull(projectDescription, "createProjectDescription returned null");
// Create one configuration description
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
IProjectType type = ManagedBuildManager.getProjectType(projectType);
Assert.isNotNull(type, "project type not found");
ManagedProject mProj = new ManagedProject(project, type);
info.setManagedProject(mProj);
IConfiguration[] cfgs = type.getConfigurations();
Assert.isNotNull(cfgs, "configurations not found");
Assert.isTrue(cfgs.length > 0, "no configurations found in the project type");
String configurationName = null;
String os = System.getProperty("os.name");
switch(interfaceType) {
case T_ARM:
configurationName = ARM_CONFIGURATION_ID;
break;
case T_CFV1:
case T_CFVX:
configurationName = COLDFIRE_CONFIGURATION_ID;
break;
}
for (IConfiguration configuration : cfgs) {
String configId = configuration.getId();
if (!configId.startsWith(configurationName)) {
continue;
}
String id = ManagedBuildManager.calculateChildId(configuration.getId(), null);
Configuration config = new Configuration(mProj, (Configuration) configuration, id, false, true, false);
config.setArtifactName(artifactName);
CConfigurationData data = config.getConfigurationData();
Assert.isNotNull(data, "data is null for created configuration");
projectDescription.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
}
Assert.isTrue(projectDescription.getConfigurations().length > 0, "No Configurations!");
coreModel.setProjectDescription(project, projectDescription);
// }
if (!(hasCCNature && !project.hasNature(CCProjectNature.CC_NATURE_ID))) {
CCProjectNature.addCCNature(project, monitor.newChild(5));
}
CoreModel.getDefault().updateProjectDescriptions(new IProject[] { project }, monitor);
if (!(hasCCNature && !project.hasNature(CCProjectNature.CC_NATURE_ID))) {
CCProjectNature.addCCNature(project, monitor.newChild(5));
}
} finally {
monitor.done();
}
return project;
}
use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project usbdm-eclipse-plugins by podonoghue.
the class DisassembleCFileHandler method execute.
// public static void pipeStream(InputStream input, OutputStream output)
// throws IOException {
//
// byte buffer[] = new byte[1024];
// int numRead = 0;
//
// while (input.available() > 0) {
// numRead = input.read(buffer);
// output.write(buffer, 0, numRead);
// }
// output.flush();
// }
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String os = System.getProperty("os.name");
boolean isLinux = (os != null) && os.toUpperCase().contains("LINUX");
Object source = HandlerUtil.getCurrentSelection(event);
// System.err.println("Event source = "+source.toString()+"\n class = "+source.getClass().toString());
if (!(source instanceof TreeSelection)) {
// System.err.println("Source is not an instance of TreeSelection");
return null;
}
TreeSelection selection = (TreeSelection) source;
if (!(selection.getFirstElement() instanceof IBinary)) {
// System.err.println("Selection.getFirstElement() is not an instance of org.eclipse.cdt.core.model.IBinary");
return null;
}
IBinary binary = (IBinary) selection.getFirstElement();
IResource resource = binary.getUnderlyingResource();
IPath resourcePath = resource.getLocation();
IPath dissassemblyPath = resourcePath.removeFileExtension().addFileExtension("lis");
// Get Environment (path etc)
CoreModel cdtCoreModel = org.eclipse.cdt.core.model.CoreModel.getDefault();
ICProjectDescription cProjectDescription = cdtCoreModel.getProjectDescription(resource.getProject());
ICConfigurationDescription cConfigurationDescription = cProjectDescription.getActiveConfiguration();
IContributedEnvironment contributedEnvironment = CCorePlugin.getDefault().getBuildEnvironmentManager().getContributedEnvironment();
IEnvironmentVariable[] environmentVariablesArray = contributedEnvironment.getVariables(cConfigurationDescription);
HashMap<String, String> environmentMap = new HashMap<String, String>();
for (IEnvironmentVariable ev : environmentVariablesArray) {
String name = ev.getName();
if ((!isLinux) && name.equals("PATH")) {
name = "Path";
}
// System.err.println("Adding Environment variable: "+name+" => "+ev.getValue());
environmentMap.put(name, ev.getValue());
}
// String resourceName = resource.getName();
// System.err.println("resourceName = "+resourceName);
IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(resource);
IConfiguration configuration = buildInfo.getDefaultConfiguration();
// System.err.println("configuration = "+configuration);
// Find lister tool in configuration
ITool[] toolArray = configuration.getTools();
ITool tool = null;
for (ITool t : toolArray) {
Pattern p = Pattern.compile("net\\.sourceforge\\.usbdm\\.cdt\\..*\\.toolchain\\.lister\\..*");
if (p.matcher(t.getId()).matches()) {
tool = configuration.getTool(t.getId());
break;
}
}
if (tool == null) {
return null;
}
// System.err.println("tool.getName = "+tool.getName());
// System.err.println("tool.getToolCommand = "+tool.getToolCommand());
// Get command line generator
IManagedCommandLineGenerator commandLineGenerator = tool.getCommandLineGenerator();
// Get command line
try {
String[] inputs = { resourcePath.lastSegment() };
IManagedCommandLineInfo commandLineInfo = commandLineGenerator.generateCommandLineInfo(tool, tool.getToolCommand(), tool.getToolCommandFlags(resourcePath, dissassemblyPath), "", ">", dissassemblyPath.lastSegment(), inputs, "${COMMAND} ${INPUTS} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}");
// System.err.println("cl.toString() = "+commandLineInfo.toString());
// System.err.println("cl.getCommandLine() = "+commandLineInfo.getCommandLine());
String[] commandArray = null;
if (isLinux) {
// Construct command (Use cmd for PATH changes!)
ArrayList<String> command = new ArrayList<String>(20);
command.add("/bin/sh");
command.add("-c");
command.add(commandLineInfo.getCommandLine());
commandArray = (String[]) command.toArray(new String[command.size()]);
} else {
// Construct command (Use cmd for PATH changes!)
ArrayList<String> command = new ArrayList<String>(20);
command.add("cmd.exe");
command.add("/C");
command.add(commandLineInfo.getCommandLine());
commandArray = (String[]) command.toArray(new String[command.size()]);
}
// Run command
// System.err.println("Running...");
ProcessBuilder pb = new ProcessBuilder(commandArray);
pb.environment().putAll(environmentMap);
File commandFile = findExecutableOnPath(pb.environment().get("PATH"), commandLineInfo.getCommandName());
if (commandFile != null) {
// System.err.println("commandFile.toPath() = "+ commandFile.toPath());
// System.err.println("pwd = "+ resourcePath.removeLastSegments(1).toFile());
}
// System.err.println("=================== Environment variables ===================");
// for (String envName : pb.environment().keySet()) {
// System.err.println("Environment variable: "+envName+" => "+pb.environment().get(envName));
// }
// System.err.println("=================== End of Environment variables ===================");
pb.redirectInput(Redirect.INHERIT);
pb.redirectError(Redirect.INHERIT);
pb.redirectOutput(Redirect.INHERIT);
pb.directory(resourcePath.removeLastSegments(1).toFile());
// System.err.println("WD =" + pb.directory());
Process p = pb.start();
// System.err.println("Waiting...");
p.waitFor();
// System.err.println("Exit value = " + p.waitFor());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BuildException e) {
e.printStackTrace();
}
try {
// Refresh parent directory so file is visible
resource.getParent().refreshLocal(1, null);
} catch (CoreException e) {
e.printStackTrace();
}
try {
// Open disassembled file in editor
IPath asmPath = resource.getFullPath().removeFileExtension().addFileExtension("lis");
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IDE.openEditor(page, ResourcesPlugin.getWorkspace().getRoot().getFile(asmPath));
} catch (PartInitException e) {
e.printStackTrace();
}
// System.err.println("Completed");
return null;
}
Aggregations