Search in sources :

Example 6 with SloeberProject

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

the class resourceChangeListener method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    // we are only interested in POST_CHANGE events
    if (event.getType() != IResourceChangeEvent.POST_CHANGE)
        return;
    final ArrayList<IProject> changedSloeberCfgFiles = new ArrayList<>();
    IResourceDelta rootDelta = event.getDelta();
    for (IResourceDelta projectDelta : rootDelta.getAffectedChildren()) {
        IResourceDelta sloeberCfgDelta = projectDelta.findMember(new Path(SLOEBER_CFG));
        if (sloeberCfgDelta != null) {
            if (sloeberCfgDelta.getKind() != IResourceDelta.REMOVED) {
                IProject iProject = sloeberCfgDelta.getResource().getProject();
                // stop the indexer
                IndexerController.doNotIndex(iProject);
                // log to process later
                changedSloeberCfgFiles.add(iProject);
            }
        } else {
            // it is not a new type Sloeber project check whether it is an old type Sloeber
            // project
            // $NON-NLS-1$
            IResourceDelta cProjectDelta = projectDelta.findMember(new Path(".cproject"));
            if (cProjectDelta != null)
                if (projectDelta.getFlags() == IResourceDelta.OPEN) {
                    // as it is a open of a cdt project assume it is a sloeber project.
                    // We will find out later if not
                    IProject iProject = cProjectDelta.getResource().getProject();
                    SloeberProject curSloeberProject = SloeberProject.getSloeberProject(iProject);
                    if (curSloeberProject != null) {
                        if (!curSloeberProject.isInMemory()) {
                            // stop the indexer
                            IndexerController.doNotIndex(iProject);
                            curSloeberProject.configure();
                        }
                    }
                // log to process later
                // changedSloeberCfgFiles.add(iProject);
                }
        }
    }
    // no sloeber.cfg files have been modified
    if (changedSloeberCfgFiles.size() == 0)
        return;
    Job job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Sloeber.cfg modification processor") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IWorkspaceRoot root = workspace.getRoot();
            ICoreRunnable runnable = new ICoreRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    for (IProject curProject : changedSloeberCfgFiles) {
                        if (curProject.isOpen()) {
                            SloeberProject curSloeberProject = SloeberProject.getSloeberProject(curProject);
                            if (curSloeberProject == null) {
                            // this is not a sloeber project;
                            // make it one?
                            } else {
                                // no use updating the cfg if it wasn't read already
                                if (curSloeberProject.isInMemory()) {
                                    curSloeberProject.sloeberCfgChanged();
                                }
                            }
                        }
                        IndexerController.index(curProject);
                    }
                }
            };
            try {
                workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, null);
            } catch (Exception e) {
                Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "failed to start sloeber.cfg updater", // $NON-NLS-1$
                e));
            }
            return Status.OK_STATUS;
        }
    };
    job.setPriority(Job.SHORT);
    job.schedule();
}
Also used : Path(org.eclipse.core.runtime.Path) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) SloeberProject(io.sloeber.core.api.SloeberProject) ICoreRunnable(org.eclipse.core.runtime.ICoreRunnable) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) Job(org.eclipse.core.runtime.jobs.Job) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 7 with SloeberProject

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

the class ConfigurationChangeListener method handleEvent.

@Override
public void handleEvent(CProjectDescriptionEvent event) {
    IProject activeProject = event.getProject();
    SloeberProject sloeberProject = SloeberProject.getSloeberProject(activeProject);
    if (sloeberProject == null) {
        // this is not a sloeber project so ignore
        return;
    }
    // don't do stuff during project creation
    if (IndexerController.isPosponed(activeProject)) {
        Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(), // $NON-NLS-1$
        "Ignoring configuration change during project creation " + activeProject.getName()));
        return;
    }
    switch(event.getEventType()) {
        case CProjectDescriptionEvent.ABOUT_TO_APPLY:
            {
                ICProjectDescription newProjDesc = event.getNewCProjectDescription();
                ICProjectDescription oldProjDesc = event.getOldCProjectDescription();
                sloeberProject.configChangeAboutToApply(newProjDesc, oldProjDesc);
                break;
            }
        default:
            {
            // should not happen
            }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) SloeberProject(io.sloeber.core.api.SloeberProject) IProject(org.eclipse.core.resources.IProject)

Example 8 with SloeberProject

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

the class SloeberBuildRunner method invokeBuild.

@Override
public boolean invokeBuild(int kind, IProject project, IConfiguration configuration, IBuilder builder, IConsole console, IMarkerGenerator markerGenerator, IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor) throws CoreException {
    String theBuildTarget = builder.getFullBuildTarget();
    String actualUploadPort = Const.EMPTY;
    List<String> stopSerialOnBuildTargets = List.of(Preferences.getDisconnectSerialTargetsList());
    if (stopSerialOnBuildTargets.contains(theBuildTarget)) {
        SloeberProject sloeberProject = SloeberProject.getSloeberProject(project);
        if (sloeberProject != null) {
            BoardDescription myBoardDescriptor = sloeberProject.getBoardDescription(configuration.getName(), true);
            if (myBoardDescriptor != null) {
                actualUploadPort = myBoardDescriptor.getActualUploadPort();
                if (actualUploadPort == null) {
                    actualUploadPort = Const.EMPTY;
                }
            }
        }
    }
    boolean theComPortIsPaused = false;
    if (!actualUploadPort.isBlank()) {
        try {
            theComPortIsPaused = SerialManager.pauseSerialMonitor(actualUploadPort);
        } catch (Exception e) {
            Status ret = new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, Messages.Upload_Error_com_port, e);
            Common.log(ret);
        }
    }
    Job job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Start build Activator") {

        @Override
        protected IStatus run(IProgressMonitor _monitor) {
            try {
                // $NON-NLS-1$
                String buildflag = "FbStatus";
                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', '/', 'b', 'u', 'i', 'l', 'd', 'S', 't', 'a', 'r', 't', '.', 'h', 't', 'm', 'l', '?', 'b', '=' };
                IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
                int curFsiStatus = myScope.getInt(buildflag, 0) + 1;
                myScope.putInt(buildflag, curFsiStatus);
                try {
                    myScope.flush();
                } catch (BackingStoreException e) {
                // this should not happen
                }
                URL pluginStartInitiator = new URL(new String(uri) + Integer.toString(curFsiStatus));
                pluginStartInitiator.getContent();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return Status.OK_STATUS;
        }
    };
    job.setPriority(Job.DECORATE);
    job.schedule();
    boolean ret = super.invokeBuild(kind, project, configuration, builder, console, markerGenerator, projectBuilder, monitor);
    if (theComPortIsPaused) {
        try {
            SerialManager.resumeSerialMonitor(actualUploadPort);
        } catch (Exception e) {
            Status ret2 = new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, Messages.Upload_Error_serial_monitor_restart, e);
            Common.log(ret2);
        }
    }
    return ret;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) SloeberProject(io.sloeber.core.api.SloeberProject) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) CoreException(org.eclipse.core.runtime.CoreException) BackingStoreException(org.osgi.service.prefs.BackingStoreException) URL(java.net.URL) BoardDescription(io.sloeber.core.api.BoardDescription) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 9 with SloeberProject

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

the class SloeberConfigurationVariableSupplier method getVariables.

@Override
public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration, IEnvironmentVariableProvider provider) {
    Map<String, String> retVars = new HashMap<>();
    Map<String, String> workbenchVars = BoardsManager.getEnvironmentVariables();
    if (workbenchVars != null) {
        retVars.putAll(workbenchVars);
    }
    SloeberProject sloeberProject = getSloeberProject(configuration);
    if (sloeberProject != null) {
        Map<String, String> boardEnvVars = sloeberProject.getEnvironmentVariables(configuration.getName());
        if (boardEnvVars != null) {
            retVars.putAll(boardEnvVars);
        }
    }
    IBuildEnvironmentVariable[] ret = new BuildEnvironmentVariable[retVars.size()];
    int i = 0;
    for (Entry<String, String> curVar : retVars.entrySet()) {
        ret[i++] = new BuildEnvironmentVariable(curVar.getKey(), curVar.getValue());
    }
    return ret;
}
Also used : IBuildEnvironmentVariable(org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable) HashMap(java.util.HashMap) SloeberProject(io.sloeber.core.api.SloeberProject) IBuildEnvironmentVariable(org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable)

Example 10 with SloeberProject

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

the class SloeberConfigurationVariableSupplier method getVariable.

@Override
public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration, IEnvironmentVariableProvider provider) {
    String ret = null;
    SloeberProject sloeberProject = getSloeberProject(configuration);
    if (sloeberProject == null) {
        return null;
    }
    Map<String, String> boardEnvVars = sloeberProject.getEnvironmentVariables(configuration.getName());
    if (null != boardEnvVars) {
        ret = boardEnvVars.get(variableName);
    }
    if (ret == null) {
        // when the configuration doesn't hold the env var maybe the workbench does
        ret = BoardsManager.getEnvironmentVariables().get(variableName);
    }
    if (ret == null) {
        return null;
    }
    return new BuildEnvironmentVariable(variableName, ret);
}
Also used : IBuildEnvironmentVariable(org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable) SloeberProject(io.sloeber.core.api.SloeberProject)

Aggregations

SloeberProject (io.sloeber.core.api.SloeberProject)12 IProject (org.eclipse.core.resources.IProject)8 BoardDescription (io.sloeber.core.api.BoardDescription)6 Status (org.eclipse.core.runtime.Status)5 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)4 CoreException (org.eclipse.core.runtime.CoreException)4 CodeDescription (io.sloeber.core.api.CodeDescription)3 CompileDescription (io.sloeber.core.api.CompileDescription)3 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)3 IStatus (org.eclipse.core.runtime.IStatus)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 IBuildEnvironmentVariable (org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 PartInitException (org.eclipse.ui.PartInitException)2 OtherDescription (io.sloeber.core.api.OtherDescription)1 File (java.io.File)1 URL (java.net.URL)1