Search in sources :

Example 1 with BoardDescriptor

use of io.sloeber.core.api.BoardDescriptor in project arduino-eclipse-plugin by Sloeber.

the class Libraries method findAllHarwareLibraries.

/**
 * Searches all the hardware dependent libraries of a project. If this is a
 * board referencing a core then the libraries of the referenced core are
 * added as well
 *
 * @param project
 *            the project to find all hardware libraries for
 * @return all the library folder names. May contain empty values.
 */
private static Map<String, IPath> findAllHarwareLibraries(ICConfigurationDescription confdesc) {
    Map<String, IPath> ret = new HashMap<>();
    BoardDescriptor boardDescriptor = new InternalBoardDescriptor(confdesc);
    // first add the referenced
    IPath libPath = boardDescriptor.getReferencedLibraryPath();
    if (libPath != null) {
        ret.putAll(findAllSubFolders(libPath));
    }
    // then add the referencing
    libPath = boardDescriptor.getReferencingLibraryPath();
    if (libPath != null) {
        ret.putAll(findAllSubFolders(libPath));
    }
    return ret;
}
Also used : IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) InternalBoardDescriptor(io.sloeber.core.InternalBoardDescriptor) BoardDescriptor(io.sloeber.core.api.BoardDescriptor) InternalBoardDescriptor(io.sloeber.core.InternalBoardDescriptor)

Example 2 with BoardDescriptor

use of io.sloeber.core.api.BoardDescriptor 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 3 with BoardDescriptor

use of io.sloeber.core.api.BoardDescriptor 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 4 with BoardDescriptor

use of io.sloeber.core.api.BoardDescriptor in project arduino-eclipse-plugin by Sloeber.

the class NewSketchWizard method createProjectWrapper.

protected void createProjectWrapper(IProgressMonitor monitor) {
    BoardDescriptor boardID = this.mArduinoPage.getBoardID();
    CodeDescriptor codeDescription = this.mNewArduinoSketchWizardCodeSelectionPage.getCodeDescription();
    try {
        this.mProject = boardID.createProject(this.mWizardPage.getProjectName(), (!this.mWizardPage.useDefaults()) ? this.mWizardPage.getLocationURI() : null, ConfigurationDescriptor.getDefaultDescriptors(), codeDescription, new CompileOptions(null), monitor);
    } catch (Exception e) {
        this.mProject = null;
        Activator.log(new Status(IStatus.ERROR, Activator.getId(), Messages.ui_new_sketch_error_failed_to_create_project, e));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CompileOptions(io.sloeber.core.api.CompileOptions) BoardDescriptor(io.sloeber.core.api.BoardDescriptor) CodeDescriptor(io.sloeber.core.api.CodeDescriptor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with BoardDescriptor

use of io.sloeber.core.api.BoardDescriptor in project arduino-eclipse-plugin by Sloeber.

the class CreateAndCompileArduinoIDEExamplesOnTeensyTest method testExample.

public void testExample(MCUBoard board) {
    // failures
    if (totalFails >= maxFails) {
        fail("To many fails. Stopping test");
    }
    if (!board.isExampleSupported(myExample)) {
        return;
    }
    Map<String, String> boardOptions = board.getBoardOptions(myExample);
    BoardDescriptor boardDescriptor = board.getBoardDescriptor();
    boardDescriptor.setOptions(boardOptions);
    BuildAndVerify(boardDescriptor);
}
Also used : BoardDescriptor(io.sloeber.core.api.BoardDescriptor)

Aggregations

BoardDescriptor (io.sloeber.core.api.BoardDescriptor)16 CodeDescriptor (io.sloeber.core.api.CodeDescriptor)8 HashMap (java.util.HashMap)7 CoreException (org.eclipse.core.runtime.CoreException)7 IPath (org.eclipse.core.runtime.IPath)7 Test (org.junit.Test)7 CompileOptions (io.sloeber.core.api.CompileOptions)6 IProject (org.eclipse.core.resources.IProject)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)4 ArrayList (java.util.ArrayList)3 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)3 TreeMap (java.util.TreeMap)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Parameters (org.junit.runners.Parameterized.Parameters)2 InternalBoardDescriptor (io.sloeber.core.InternalBoardDescriptor)1 MCUBoard (io.sloeber.providers.MCUBoard)1 File (java.io.File)1 IOException (java.io.IOException)1