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();
}
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
}
}
}
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;
}
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;
}
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);
}
Aggregations