Search in sources :

Example 6 with ICProjectDescription

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) TreeMap(java.util.TreeMap)

Example 7 with ICProjectDescription

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();
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) URL(java.net.URL) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) BoardDescriptor(io.sloeber.core.api.BoardDescriptor) Job(org.eclipse.core.runtime.jobs.Job)

Example 8 with ICProjectDescription

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;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IContributedEnvironment(org.eclipse.cdt.core.envvar.IContributedEnvironment) IEnvironmentVariableManager(org.eclipse.cdt.core.envvar.IEnvironmentVariableManager) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IOException(java.io.IOException) BoardDescriptor(io.sloeber.core.api.BoardDescriptor) IOException(java.io.IOException)

Example 9 with ICProjectDescription

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;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) Configuration(org.eclipse.cdt.managedbuilder.internal.core.Configuration) IProjectType(org.eclipse.cdt.managedbuilder.core.IProjectType) SubMonitor(org.eclipse.core.runtime.SubMonitor) CConfigurationData(org.eclipse.cdt.core.settings.model.extension.CConfigurationData) IProject(org.eclipse.core.resources.IProject) InterfaceType(net.sourceforge.usbdm.constants.UsbdmSharedConstants.InterfaceType) CoreModel(org.eclipse.cdt.core.model.CoreModel) ManagedBuildInfo(org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo) ManagedProject(org.eclipse.cdt.managedbuilder.internal.core.ManagedProject) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Example 10 with ICProjectDescription

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;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeSelection(org.eclipse.jface.viewers.TreeSelection) PartInitException(org.eclipse.ui.PartInitException) Pattern(java.util.regex.Pattern) IPath(org.eclipse.core.runtime.IPath) IManagedCommandLineGenerator(org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator) IBinary(org.eclipse.cdt.core.model.IBinary) IOException(java.io.IOException) ITool(org.eclipse.cdt.managedbuilder.core.ITool) IContributedEnvironment(org.eclipse.cdt.core.envvar.IContributedEnvironment) IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) CoreException(org.eclipse.core.runtime.CoreException) IManagedCommandLineInfo(org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo) CoreModel(org.eclipse.cdt.core.model.CoreModel) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEnvironmentVariable(org.eclipse.cdt.core.envvar.IEnvironmentVariable) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Aggregations

ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)45 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)31 CoreException (org.eclipse.core.runtime.CoreException)17 IProject (org.eclipse.core.resources.IProject)13 Status (org.eclipse.core.runtime.Status)10 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)9 IPath (org.eclipse.core.runtime.IPath)9 IStatus (org.eclipse.core.runtime.IStatus)9 CCorePlugin (org.eclipse.cdt.core.CCorePlugin)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)7 IOException (java.io.IOException)5 BoardDescription (io.sloeber.core.api.BoardDescription)4 CodeDescription (io.sloeber.core.api.CodeDescription)4 CompileDescription (io.sloeber.core.api.CompileDescription)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 BoardDescriptor (io.sloeber.core.api.BoardDescriptor)3